comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca>
Subject: Re: Trying to import a C function
Date: Thu, 06 Nov 2003 12:11:16 -0500
Date: 2003-11-06T12:11:16-05:00	[thread overview]
Message-ID: <pgvqb.21199$mB5.925473@news20.bellglobal.com> (raw)
In-Reply-To: <jbtqb.92859$ao4.278990@attbi_s51>

Steve wrote:
> "Preben Randhol" <randhol+valid_for_reply_from_news@pvv.org> wrote in
> message
> news:slrnbqk7aq.q3.randhol+valid_for_reply_from_news@kiuk0156.chembio.ntnu.no...
> 
>>Hi
> 
> [snip]
> 
>>Now what is the equivalent of unsigned long long int in Ada?
> 
> In GNAT on x86:
> 
>   unsigned long long   =  Interfaces.Unsigned_64
> 
> You could define your own using a modular type definition, but isn't that
> the reason the Interfaces module is there in the first place?
> 
> Steve
> (The Duck)

I find that it is generally easier, and more portable, to handle
macros and size differences in a C wrapper function. This
particularly applies to Linux, since so much changes there still.

If you enforce a parameter size of 64 bits between your C wrapper
and the Ada code, you can always be assured that you won't get
burned on the size differences.

Furthermore, if you are targeting multiple platforms/UNIces, then
the structure definition, its padding and alignment will also
give you trouble (and in fact this can potentially be the case
with different Linux releases/distros). For this reason, it is
sometimes better to have the C wrapper take the structure
elements and pass them back to Ada in safe sized arguments
individually (or perhaps stable structure definitions that
guarantee sizes and alignments).

If you use the C wrapper approach, you have a better chance of
only visiting that code once. If you choose to avoid the
wrapper, you'll likely be looking at the interface again,
with the next release or platform. ;-)

The only other alternative is to run a process that generates
the interface (or interface parameters) prior to compiling. I
believe that FLORIST does something along this line (but
it has been a while since I have looked at that side of
things).

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




  reply	other threads:[~2003-11-06 17:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-06 10:07 Trying to import a C function Preben Randhol
2003-11-06 10:40 ` Lutz Donnerhacke
2003-11-06 16:05   ` Preben Randhol
2003-11-07 15:02     ` Adrian Knoth
2003-11-07 15:13       ` Preben Randhol
2003-11-10 14:39     ` Lutz Donnerhacke
2003-11-10 16:10       ` Preben Randhol
2003-11-10 16:45         ` Adrian Knoth
2003-11-06 14:48 ` Steve
2003-11-06 17:11   ` Warren W. Gay VE3WWG [this message]
2003-11-07  8:44     ` Preben Randhol
2003-11-10 17:39       ` Warren W. Gay VE3WWG
2003-11-11  8:26         ` Preben Randhol
replies disabled

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