comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: acceess problem
Date: Tue, 26 Jul 2011 10:43:22 -0700 (PDT)
Date: 2011-07-26T10:43:22-07:00	[thread overview]
Message-ID: <980bda39-954a-4b4e-8b7d-fb9597f808c0@s33g2000prg.googlegroups.com> (raw)
In-Reply-To: 8727ccd3-d7e9-4d41-b55c-9c3d4fba1a78@df3g2000vbb.googlegroups.com

On Jul 26, 8:57 am, Gautier write-only <gautier_niou...@hotmail.com>
wrote:
> On 25 juil, 10:27, Simon Wright <si...@pushface.org> wrote:
>
> > Replace 'Access with 'Unchecked_Access or, if that doesn't work, with
> > the (GNAT-special) 'Unrestricted_Access.
>
> Unless 'Unrestricted_Access has been inbetween added to the language,
> there is a way to have it in a pure Ada form:
>
>   function Cvt is new
> Ada.Unchecked_Conversion(System.Address,DoublePtr);
>   -- This method is functionally identical as GNAT's
> Unrestricted_Access
>   -- but has no type safety (cf GNAT Docs)
>   pragma No_Strict_Aliasing(DoublePtr); -- recommended by GNAT 2005
>
>   procedure Vertex (v: Double_vector_3D) is
>   begin
>     Vertex3dv(Cvt(v(0)'Address));
>   end Vertex;
>
> ^this is an excerpt from an existing GL binding (why reinvent it?)...http://globe3d.svn.sourceforge.net/viewvc/globe3d/bindings/gl.adb?rev...

Although I don't like this approach, if you're going to convert an
Address to an access object, surely it's better to use
System.Address_To_Access_Conversions, which is designed for this sort
of conversion, than to use Unchecked_Conversion, which assumes that a
System.Address and the access object you're converting to have the
same format, which isn't always the case.  There's no point in using
"pure Ada" if it results in code that compiles on another system but
doesn't work properly.

                              -- Adam



  reply	other threads:[~2011-07-26 17:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-24 15:59 acceess problem ldries46
2011-07-24 17:27 ` Simon Wright
2011-07-25  6:57   ` ldries46
2011-07-25  8:27     ` Simon Wright
2011-07-25  9:59       ` ldries46
2011-07-26 15:57       ` Gautier write-only
2011-07-26 17:43         ` Adam Beneschan [this message]
2011-07-27 12:06           ` Gautier write-only
2011-07-25  9:08     ` AdaMagica
replies disabled

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