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: Simon Wright Subject: Re: Access conversions Date: 1998/10/13 Message-ID: #1/1 X-Deja-AN: 400873985 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 908341295 nnrp-09:27350 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada Date: 1998-10-13T00:00:00+00:00 List-Id: stt@houdini.camb.inmet.com (Tucker Taft) writes: > 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; [...] > : 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. And this also works if the parameter is just G : Graph. Cool. I must say, this area is a touch complex; I tried return V.Rep.Enclosing = G'Access; bc-graphs.adb:191:32: object has deeper accessibility level than access type return V.Rep.Enclosing = Graph_Ptr (G'Access); bc-graphs.adb:191:32: argument of conversion cannot be access bc-graphs.adb:191:44: operand type has deeper accessibility level than target return V.Rep.Enclosing.all'Access = G'Access; bc-graphs.adb:191:41: two access attributes cannot be compared directly bc-graphs.adb:191:41: they must be converted to an explicit type for comparison so as you can see I was scratching around rather reprehensibly. The right way to do things is usually obviously right, though not always obvious. > : 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. Well, V.Rep.Enclosing _shouldn't_ ever be null; there should perhaps be a validation in there .. > -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ > Intermetrics, Inc. Burlington, MA USA > An AverStar Company -Simon