From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: System.Address to Access to function/procedure conversion
Date: Sun, 28 Jul 2013 13:04:03 -0700
Date: 2013-07-28T13:04:03-07:00 [thread overview]
Message-ID: <kt3t3j$4cn$2@dont-email.me> (raw)
In-Reply-To: <kt3q2a$18qs$2@adenine.netfront.net>
On 07/28/2013 12:05 PM, Tarek Ghaleb wrote:
>
> Interesting, I thought System.Address was equivalent to a C pointer,
> and I've seen it used that way in many snippets of code, etc. For
> things like void*, if not represented as System.Address, how would it
> be represented then?
Such code is compiler-dependent. GNAT usually (always?) maintains a
correspondence between hardware address, System.Address, access types, and C
pointers, but I've certainly used compilers where that wasn't true. I recall one
system written originally with GNAT that was ported to Rational (same platform).
The code used Unchecked_Conversion between access types and System.Address,
which failed miserably on Rational, where the 2 were not the same. It had to be
revised to use System.Address_To_Access_Conversions, which was not a trivial
undertaking. Moral: it's usually cheaper to write portable code in the 1st place.
A void* passed between C and Ada is usually C's equivalent of a private type,
with all values coming from C and never dereferenced by Ada. For such cases, all
that we need to model in Ada is that what we have is a C pointer. The
implementation usually looks like
type Void is null record;
type Void_Ptr is access all Void;
pragma Convention (C, Void_Ptr);
Of course, there's no real need for type Void; Void_Ptr could be "access all
Integer" and it would work just as well. The advantage of using Void is that
anyone who dereferences a Void_Ptr gets something useless.
If Void_Ptr is declared publicly, it should obviously be [limited] private. And
usually there's a better name for it than Void_Ptr.
--
Jeff Carter
"Oh Lord, bless this thy hand grenade, that with it thou
mayst blow thine enemies to tiny bits, in thy mercy."
Monty Python and the Holy Grail
24
next prev parent reply other threads:[~2013-07-28 20:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-28 15:27 System.Address to Access to function/procedure conversion Tarek Ghaleb
2013-07-28 16:14 ` Dmitry A. Kazakov
2013-07-28 19:05 ` Tarek Ghaleb
2013-07-28 19:23 ` Simon Wright
2013-07-28 22:03 ` Tarek Ghaleb
2013-07-28 20:03 ` Dmitry A. Kazakov
2013-07-28 21:13 ` Shark8
2013-07-28 22:54 ` Tarek Ghaleb
2013-07-29 3:27 ` Shark8
2013-07-29 7:06 ` Tarek Ghaleb
2013-07-28 17:19 ` Jeffrey Carter
2013-07-28 19:05 ` Tarek Ghaleb
2013-07-28 20:04 ` Jeffrey Carter [this message]
2013-07-28 21:31 ` Maciej Sobczak
2013-07-29 6:26 ` Tarek Ghaleb
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox