Article View: comp.std.c++
Article #1131Re: Pointer comparisons
From: Jim Adcock
Date: Sat, 19 Dec 1992 00:18
Date: Sat, 19 Dec 1992 00:18
41 lines
1506 bytes
1506 bytes
In article <1992Dec17.151642.9954@bcrka451.bnr.ca> sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
|>4) If two pointers p and q (of the same type) are obtained through
|> sequences of "normal" operations, then
|>
|> p == q <==> p and q point to the same object
|
|I could not find this statement in the current wording. Is there a
|reason why the current wording is weaker than this?
Again, a simple counterexample is as follows:
#include <stdio.h>
class A {};
class B : public A
{
public:
A a;
};
main()
{
B b;
A* pb = &b;
A* pa = &(b.a);
if (pb == pa)
printf("equality of two legal ptrs of the same type pointing"
"at different objects");
return 0;
}
Again, my claim is that this is perfectly legal C++ code, which is commonly
implemented in some C++ compilers such that the equality test does
test true. On the contrary, for the test to not prove true would
mean that the empty base class part has to be implemented by the compiler
using gratuitous padding, and gratuitous padding is an anathema to
traditional C/C++ implementation.
Technical Details
Message-ID:
<1992Dec19.001851.22116@microsoft.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimadReferences:
<1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp> <1992Dec17.151642.9954@bcrka451.bnr.ca>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad From: jimad@microsoft.com (Jim Adcock) Subject: Re: Pointer comparisons Message-ID: <1992Dec19.001851.22116@microsoft.com> Date: 19 Dec 92 00:18:51 GMT Organization: Microsoft Corporation References: <1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp> <1992Dec17.151642.9954@bcrka451.bnr.ca> Lines: 41