comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <alejandro@mosteo.invalid>
Subject: Re: How to access this package written in C?
Date: Mon, 03 May 2010 10:12:05 +0200
Date: 2010-05-03T10:12:05+02:00	[thread overview]
Message-ID: <hrm093$52p$1@news.eternal-september.org> (raw)
In-Reply-To: hr7ofq$e2$1@munin.nbi.dk

Randy Brukardt wrote:

> ...
>>> I use this:
>>>
>>>     subtype Void_Ptr is System.Address;
>>
>> I have sometimes used
>>
>>      type Void is null record;
>>      pragma Convention (Void, C);
>>      type Void_Ptr is access all Void;
>>      pragma Convention (Void_Ptr, C);
> 
> Most of the time, I've avoided any version of void* and simply written
> overloadings for each type that I needed (using in out parameters if
> possible, or access parameters if I needed the function result). That only
> works of course when the number of types that you need is limited, and
> it's not as flexible as some more direct mapping.
> 
> But void* is exactly the opposite of strong typing, and it simply doesn't
> fit well into the Ada type model. So avoiding it if possible is the best
> approach.

I've lived both ways, and I understand your point. In the particular case I 
had in mind, the C side changed too frequently for my own good, so using an 
opaque type and passing the pointer to it to C-side routines was the less 
maintenance-intensive approach. Massaging the C data returns into my own set 
of Ada types worked well, since the trick is hidden from user code.

This reminds me of another thing that bores me about bindings, which is that 
even if you mimic C types with Ada types using convention C, these types are 
not always nice to propagate to client code, so in the end I find myself 
with even more duplicated types.



  reply	other threads:[~2010-05-03  8:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-21 16:43 How to access this package written in C? resander
2010-04-21 17:39 ` Dmitry A. Kazakov
2010-04-22 20:12 ` Björn Persson
2010-04-22 21:12 ` Keith Thompson
2010-04-23 12:58   ` resander
2010-04-23 14:15     ` Dmitry A. Kazakov
2010-04-23 14:44     ` John B. Matthews
2010-04-23 15:39       ` John B. Matthews
2010-04-26 18:16     ` Robert A Duff
2010-04-26 19:57       ` Keith Thompson
2010-04-26 21:20         ` Maciej Sobczak
2010-04-27  6:52           ` Alex R. Mosteo
2010-04-27 22:29             ` Randy Brukardt
2010-05-03  8:12               ` Alex R. Mosteo [this message]
2010-04-27  0:20         ` Robert A Duff
2010-04-27  1:01           ` Keith Thompson
2010-04-27 16:07             ` Robert A Duff
2010-04-27 22:29               ` Randy Brukardt
2010-04-27  1:31           ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox