comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Gem 39 - compiler specific?
Date: Thu, 3 Sep 2009 18:38:38 +0200
Date: 2009-09-03T18:38:38+02:00	[thread overview]
Message-ID: <1s8kuin5t96vr$.1taw9mluqlplz$.dlg@40tude.net> (raw)
In-Reply-To: 4bff103b-1797-4e2b-9dcf-7466b667c59b@d9g2000prh.googlegroups.com

On Thu, 3 Sep 2009 08:26:50 -0700 (PDT), Adam Beneschan wrote:

> On Sep 3, 12:26�am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:

>> Skewed address is not a problem here. The problem is that
>> System.Address_To_Access_Conversions should take an access type as a
>> parameter rather than declare it new. This makes its use quite limited.
> 
> I don't see any limitation, at least where To_Pointer is concerned
> (which is what the above code needed to use).  If you declare an
> instance of this package for any object type T:
> 
>   type Convert_T_Access is new System.Address_To_Access_Conversions
> (T);
> 
> then an object of type Convert_T_Access.Object_Pointer can be
> converted to any access type whose designated type is T.  I checked
> through the legality rules in 4.6, and I couldn't find a way to
> declare an access-to-T type that you couldn't convert an
> Object_Pointer to.  Thus, if you have any access type
> 
>   type Acc_T is access T;  [or access all T, or access constant T]
> 
> you can convert an address Addr to an Acc_T by saying:
> 
>   Acc_T (Convert_T_Access.To_Pointer (Addr))

But Acc_T is a pool-specific access, while Address_To_Access_Conversions
creates a general access type. Here Unchecked_Conversion between access
types is required, which AFIAK is not guaranteed to work anyway. In some
cases I use:

declare
   X : T;
   for X'Address use Addr;
   pragma Import (X);
begin
   ...

> There do seem to be some limitations on using To_Address, though; you
> can't convert an "access constant T" to an Object_Pointer, and you
> can't convert an access-to-T type that is nested inside a subprogram.

Yes, accessibility rules is another major nuisance.

> So you couldn't use To_Address on those types. Offhand, though, I'd
> guess that there is much less need for this than for To_Pointer, so
> this may not be a severe enough limitation to require fixing.

That happens quite often in generic bodies. An access type comes from a
formal parameter, Address_To_Access_Conversions is instantiated within the
generics. In many (most?) cases I used considered it, I must resort to the
old and ugly Ada programmer's friend .all'Unchecked_Access...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2009-09-03 16:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-02 20:38 Gem 39 - compiler specific? Maciej Sobczak
2009-09-02 23:20 ` Randy Brukardt
2009-09-03  7:26   ` Dmitry A. Kazakov
2009-09-03 15:26     ` Adam Beneschan
2009-09-03 16:38       ` Dmitry A. Kazakov [this message]
2009-09-03 17:27         ` Adam Beneschan
2009-09-03 20:26           ` Dmitry A. Kazakov
2009-09-03 22:06             ` Randy Brukardt
2009-09-04  7:29               ` Dmitry A. Kazakov
2009-09-04 12:07                 ` Maciej Sobczak
2009-09-04 13:06                   ` Dmitry A. Kazakov
2009-09-04 17:18                     ` Dmitry A. Kazakov
2009-09-04 20:34                     ` Maciej Sobczak
2009-09-04 22:41                   ` sjw
2009-09-05 20:45                     ` Maciej Sobczak
2009-09-06  6:54                       ` sjw
2009-09-03 21:58           ` Randy Brukardt
2009-09-04 17:26           ` Robert A Duff
2009-09-03 21:53     ` Randy Brukardt
2009-09-03  0:12 ` Adam Beneschan
replies disabled

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