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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d402e2c741db0d0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-08 03:01:12 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!tar-atanamir.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Language lawyer question: Equality on 'Access attributes Date: Thu, 08 Jan 2004 12:07:31 +0100 Message-ID: <237qvvkh5t69f30kdavtnvijpnr5iu85jl@4ax.com> References: <4LKdnRRNyv6AlmCiRVn-ig@comcast.com> NNTP-Posting-Host: tar-atanamir.cbb-automation.de (212.79.194.116) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1073559670 8436436 212.79.194.116 ([77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:4202 Date: 2004-01-08T12:07:31+01:00 List-Id: On Thu, 08 Jan 2004 02:47:24 -0500, "Robert I. Eachus" wrote: >Adam Beneschan wrote: >> Given this code: >> >> package Pak1 is >> type Ptr1 is access all Integer; >> X : aliased Integer; >> Y : aliased Integer; >> B : Boolean := X'Access = Y'Access; >> end Pak1; >> >> GNAT gives me this error: "two access attributes cannot be compared >> directly / they must be converted to an explicit type for comparison". > >GNAT is right. This is a new instance of an issue that has been around >since Ada 83. In this case, the "general" access type returned by >'Access may have no relation to type Ptr1. If you want to imagine that >the implementation has other access all Integer types around, fine. But >technically, the Access attribute returns a type for which no comparison >operations are defined. You can convert this type implicitly or >explicitly to Ptr1, and the comparison will be okay: > > B : Boolean := Ptr1(X'Access) = Ptr1(Y'Access); > >or: > > Temp: Ptr1 := X'Access; > B: Boolean := Temp = Y'Access; > >I haven't tested this code, it is very late at night. But GNAT is being >helpful in their error message. > >Why not "fix" the language so this problem doesn't occur? It works >correctly now, thank you very much! You may think you "know" what the >values in this case look like, but in the general case, the compiler >needs to know what kind of pointer to generate for the 'Access >attribute. Go find any discussion of "fat pointers" vs. thin pointers, >and for Ada a discussion of how some compilers will "pack" some access >types to require less than the space for a full address. > >In this case, the two 'Access attributes are probably going to be of the >same type. But if you are really using such a comparison in a real >program, you don't want the Boolean value to depend on which version of >which compiler you use. So you have to tell the compiler which type, >and implicitly which "=" operation to use for the comparison. One might think that X'Access is just another name for C's &X, but it isn't quite so, as Robert Eachus explained. And there is also the attribute 'Address: with System; use type System.Address; ... declare X : Integer; Y : Integer; B : Boolean := X'Address = Y'Address; -- This is OK, the same type: System.Address -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de