From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,30047505e1b73aa8 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Access conversions Date: 1998/10/12 Message-ID: #1/1 X-Deja-AN: 400240049 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-10-12T00:00:00+00:00 List-Id: 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