comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Access conversions
Date: 1998/10/12
Date: 1998-10-12T00:00:00+00:00	[thread overview]
Message-ID: <F0pu4n.EFE.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: x7v1zoe73ec.fsf@pogner.demon.co.uk

Simon Wright (simon@pogner.demon.co.uk) wrote:

: I need to write a function

:   function Is_Member (G : Graph'Class; V : Vertex'Class) return Boolean;

: where there is a type

:   type Graph_Ptr is access all Graph'Class;

: and a Vertex has a component Rep with a component Enclosing of type
: Graph_Ptr which accesses its enclosing Graph.

: In GNAT I can say in Is_Member

:       return V.Rep.Enclosing = G'Unrestricted_Access;

: but of course this isn't portable.

If, inside Is_Member, you defined:

   type Graph_Const_Ptr is access constant Graph'Class;

then you could portably say:

    return Graph_Const_Ptr(V.Rep.Enclosing) = G'Access;

because all tagged formal parameters are considered aliased.

: If I say

:   function To_Ptr is new Ada.Unchecked_Conversion (System.Address,
:                                                    Graph_Ptr);

: and then in Is_Member

:       return V.Rep.Enclosing = To_Ptr (G'Address);

: which appears to work as expected in GNAT and ObjectAda 7.1, am I in
: fact riding for a fall?

The other suggestion of using 'Address on both sides of the
equality operator seems cleaner, though as mentioned above,
G'Access for Graph_Const_Ptr is probably the cleanest, as this survives 
the case when V.Rep.Enclosing is null, whereas the .all'Address solution
would raise Constraint_Error.

: -Simon

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




  parent reply	other threads:[~1998-10-12  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-12  0:00 Access conversions Simon Wright
1998-10-12  0:00 ` Matthew Heaney
1998-10-12  0:00 ` Tucker Taft [this message]
1998-10-13  0:00   ` Simon Wright
replies disabled

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