Topic: Pointers equality (Was: C++0x)
Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Mon, 7 May 2001 23:25:44 GMT Raw View
Ruslan Abdikeev wrote:
>
> "James Kuyper Jr." <kuyper@wizard.net> wrote in message
> news:3AF54E87.C934B2C6@wizard.net...
> > Daniel James wrote:
> > > You're actually not allowed to make that comparison, stuff.x+2 and
> stuff.y
> > > are pointers to different objects.
> > Incorrect. You're not allowed to make relational
> > comparisons (<, >, <=,>, >=) except for pointers into the same object,
> > but you are allowed to compare arbitrary valid >pointers for equality (==,
> !=).
>
> I've wanted to make this correction too, but then found such a sentence in
> Standard:
>
> (5.10/1)
> "The == and the != operators have *the same semantic restrictions*,
> conversions, and result type as the relational operators except for their
> lower precedence and truth-value result... Two pointers of the same type
> compare equal iff they are both null, both point to the same object or
> function, or both point one past the end of the same array."
>
> Did I miss something?
No, I stated my case incorrectly. It's incorrect to say that you're not
allowed to perform relational comparisons on pointers except when they
point into or one past the same object. The results of relational
comparisons between pointers to different objects are explicitly said to
be unspecified in 5.9p2 (which makes it pretty pointless to bother doing
the comparison), but they are permitted. Therefore, there's no semantic
restriction on carrying out the comparison, and therefore no such
restriction is inherited by the equality comparisons. The precise clause
you specify does make the results equality comparisons defined even for
pointers to different objects: 'iff' is short for "if and only if",
which means that the results are defined in every possible case.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Ruslan Abdikeev" <ruslan_abdikeevREMOVE_IT@hotmail.com>
Date: Sun, 6 May 2001 15:11:16 GMT Raw View
"James Kuyper Jr." <kuyper@wizard.net> wrote in message
news:3AF54E87.C934B2C6@wizard.net...
> Daniel James wrote:
> > You're actually not allowed to make that comparison, stuff.x+2 and
stuff.y
> > are pointers to different objects.
> Incorrect. You're not allowed to make relational
> comparisons (<, >, <=,>, >=) except for pointers into the same object,
> but you are allowed to compare arbitrary valid >pointers for equality (==,
!=).
I've wanted to make this correction too, but then found such a sentence in
Standard:
(5.10/1)
"The == and the != operators have *the same semantic restrictions*,
conversions, and result type as the relational operators except for their
lower precedence and truth-value result... Two pointers of the same type
compare equal iff they are both null, both point to the same object or
function, or both point one past the end of the same array."
Did I miss something?
Sincerely,
Ruslan Abdikeev
VR-1 Entertainment Corp.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]