From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Language lawyer question: Equality on 'Access attributes
Date: Thu, 08 Jan 2004 02:47:24 -0500
Date: 2004-01-08T02:47:24-05:00 [thread overview]
Message-ID: <4LKdnRRNyv6AlmCiRVn-ig@comcast.com> (raw)
In-Reply-To: <b4682ab7.0401071805.5bc07078@posting.google.com>
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
next prev parent reply other threads:[~2004-01-08 7:47 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-08 2:05 Language lawyer question: Equality on 'Access attributes Adam Beneschan
2004-01-08 7:47 ` Robert I. Eachus [this message]
2004-01-08 11:07 ` Dmitry A. Kazakov
2004-01-08 17:18 ` Adam Beneschan
2004-01-08 18:04 ` Robert A Duff
2004-01-08 18:31 ` Ze Administrator
2004-01-08 21:04 ` Robert A Duff
2004-01-09 4:02 ` Ze Administrator
2004-01-09 23:02 ` Robert A Duff
2004-01-10 2:56 ` Ze Administrator
2004-01-09 4:06 ` Ze Administrator
2004-01-09 23:05 ` Robert A Duff
2004-01-10 3:03 ` Ze Administrator
2004-01-10 13:47 ` Marin David Condic
2004-01-10 7:19 ` Robert I. Eachus
2004-01-10 19:09 ` Robert A Duff
2004-01-11 14:27 ` Robert I. Eachus
2004-01-11 21:42 ` Ze Administrator
2004-01-12 5:16 ` Robert I. Eachus
2004-01-09 1:28 ` Adam Beneschan
2004-01-09 4:10 ` Ze Administrator
2004-01-09 11:27 ` Dmitry A. Kazakov
2004-01-09 23:09 ` Robert A Duff
2004-01-10 11:56 ` Dmitry A. Kazakov
2004-01-10 17:08 ` Robert I. Eachus
2004-01-10 18:40 ` Robert A Duff
2004-01-09 23:08 ` Robert A Duff
2004-01-10 7:39 ` Robert I. Eachus
2004-01-08 20:36 ` tmoran
2004-01-08 21:06 ` Robert A Duff
2004-01-09 0:27 ` Randy Brukardt
2004-01-09 1:23 ` Adam Beneschan
2004-01-09 1:38 ` Robert A Duff
2004-01-09 6:16 ` Robert I. Eachus
2004-01-09 23:27 ` Randy Brukardt
2004-01-10 16:37 ` Robert I. Eachus
[not found] ` <hmfvc1-f73.ln1@beastie.ix.netcom.com>
[not found] ` <l7v1d1-n33.ln1@beastie.ix.netcom.com>
2004-01-09 23:19 ` Robert A Duff
2004-01-09 23:21 ` Randy Brukardt
-- strict thread matches above, loose matches on Subject: below --
2004-01-09 5:48 christoph.grein
2004-01-09 6:03 christoph.grein
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox