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: Matthew Heaney Subject: Re: Access conversions Date: 1998/10/12 Message-ID: #1/1 X-Deja-AN: 400153188 Sender: matt@mheaney.ni.net References: NNTP-Posting-Date: Mon, 12 Oct 1998 00:07:09 PDT Newsgroups: comp.lang.ada Date: 1998-10-12T00:00:00+00:00 List-Id: Simon Wright writes: > 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 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? > > -Simon Instead of converting the address to an access type, and then comparing access types, why not compare addresses directly: return V.Rep.Enclosing.all'Address = G'Address; Isn't this portable?