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,FREEMAIL_FROM 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-07 23:47:43 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.mathworks.com!wn13feed!worldnet.att.net!216.166.71.14!border3.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 08 Jan 2004 01:47:41 -0600 Date: Thu, 08 Jan 2004 02:47:24 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Language lawyer question: Equality on 'Access attributes References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4LKdnRRNyv6AlmCiRVn-ig@comcast.com> NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-3FYjLXRF+tjhtV58eAVjUphnboEkpF1znUa48IcA39/TohoWRtDK5qjZvJi/ZtpTWNXmUVzIFuzXNdq!Zjmk7QAu9bXpUFUEda1O/zjbyCeBcUVODJC0QJ2mLgQ3OskIL2JiahuNCNU9Xw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:4196 Date: 2004-01-08T02:47:24-05:00 List-Id: 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. -- Robert I. Eachus "The war on terror is a different kind of war, waged capture by capture, cell by cell, and victory by victory. Our security is assured by our perseverance and by our sure belief in the success of liberty." -- George W. Bush