comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: How to access this package written in C?
Date: Mon, 26 Apr 2010 14:16:31 -0400
Date: 2010-04-26T14:16:31-04:00	[thread overview]
Message-ID: <wccpr1m6pvk.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: e98bcf01-46cc-44dd-b57b-3cc7e273d9e2@j21g2000yqh.googlegroups.com

resander <kresander@gmail.com> writes:

> On Apr 22, 10:12�pm, Keith Thompson <ks...@mib.org> wrote:
>> There is no guarantee that an int can hold the value of an address,
>> and there are common systems (including Linux systems) where it
>> can't. �Worse, you're not likely to get a warning if you convert
>> a pointer to int, even if there's a loss of information.

Why?  I'd think if int is smaller than whatever*, then
a cast to int clearly deserves a warning.

>> The right type for this parameter is void* (which is roughly
>> analogous to Ada's System.Address).

Yeah, roughly.  System.Address is somewhat lower level than
C's void*.

> Thank you all for your concerns about using an int for passing an
> address. The interface actually uses a void * (could also be char * as
> that is what is needed), but I changed it for the post because I
> thought an all-int interface would be easier to handle at the Ada-to-C
> boundary. That seems to have backfired!

You should look at section B (especially B.3) of the Ada RM.
There's a type char_star you can use.

There's no void_star.  I'm not sure why -- probably this
part of Ada predates void* in C, and nobody bothered
to upgrade Ada to match the new C.

> Q1.
> Addresses are not negative. How do I output a System.Address?

In GNAT, there is a function System.Address_Image.
Look at the file s-addima.ads in your GNAT
distribution.

Beware: this is not portable to other Ada compilers.

- Bob



  parent reply	other threads:[~2010-04-26 18:16 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 [this message]
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
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