From: Alex R. Mosteo on
Maciej Sobczak wrote:

> On 26 Kwi, 21:57, Keith Thompson <ks...(a)mib.org> wrote:
>
>> But C still requires char* and void* to have the same representation.
>>
>> But in the Ada RM, I only see char_star in an example:
>>
>> subtype Char_Star is Char_Ptrs.Pointer;
>
> 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);

Curious here about any implications of using the different approaches.

When doing bindings I tend to avoid 'Access and 'Address whenever possible,
though; using in out parameters seems to be sufficient in the 99% of cases.

On the one hand I like to remain as high-level as possible; on the other I
could see that System.Address leaves less room for compiler fancies...

> It works like a charm. Please note that in order to link Ada with C
> there is a need for a *pair* of *compatible* compilers - you cannot
> compile the Ada part with a random Ada compiler and a C part with a
> random C compiler and expect them to work together. There is a lot of
> hand-waving in the multilanguage development, which means lots of
> under-the-table assumptions can be taken for granted even though they
> are not explicitly covered by any of the language standards.
>
> --
> Maciej Sobczak * http://www.inspirel.com
>
> YAMI4 - Messaging Solution for Distributed Systems
> http://www.inspirel.com/yami4

From: Robert A Duff on
Keith Thompson <kst-u(a)mib.org> writes:

> I did. <http://www.ada-auth.org/arm.html> has links to several versions
> of the Ada 2005 RM. "RM-Final.pdf" is byte-for-byte identical to the
> version I'm using, and has the above-quoted text on the title page.

Sorry for the misinformation.

> Thanks, I'll do that. I seem to recall they expect some particular
> format for comments (it's been a long time since I've submitted any); is
> that still the case, or should I just send free-form English text?

I think there are instructions near the beginning of the RM.
I think if you disobey those instructions, your comment
will still get processed and shipped out to the mailing
list.

I think you're not supposed to cc: other addresses
when sending to ada-comment(a)ada-auth.org.

But Randy is the expert on these procedures.

- Bob
From: Randy Brukardt on
....
>> 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.

Randy.





From: Randy Brukardt on
"Robert A Duff" <bobduff(a)shell01.TheWorld.com> wrote in message
news:wccbpd4x4j9.fsf(a)shell01.TheWorld.com...
> Keith Thompson <kst-u(a)mib.org> writes:
>
>> I did. <http://www.ada-auth.org/arm.html> has links to several versions
>> of the Ada 2005 RM. "RM-Final.pdf" is byte-for-byte identical to the
>> version I'm using, and has the above-quoted text on the title page.
>
> Sorry for the misinformation.
>
>> Thanks, I'll do that. I seem to recall they expect some particular
>> format for comments (it's been a long time since I've submitted any); is
>> that still the case, or should I just send free-form English text?
>
> I think there are instructions near the beginning of the RM.
> I think if you disobey those instructions, your comment
> will still get processed and shipped out to the mailing
> list.
>
> I think you're not supposed to cc: other addresses
> when sending to ada-comment(a)ada-auth.org.
>
> But Randy is the expert on these procedures.

Bob got these right this time. :-)

Randy.


From: Alex R. Mosteo on
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.