🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1271

Re: Must derived class reserve space for an empty base class?

#1271
From: Jim Adcock
Date: Wed, 16 Dec 1992 20:28
45 lines
1565 bytes
In article <5386@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
|That two non-generic pointers of the same type (possibly converted from
|pointer-to-derived) to different objects or data members should be
|guaranteed to compare unequal.
|
|Please? (:-)

Either you are misstating what you think you are stating, or I am 
misunderstanding what you are stating, or else I strongly disagree,
because I would counterclaim that pointer equality in the following
example is a legal and perfectly reasonable, and efficient, implementation.
On the contrary, requiring unnecessary and unexpected padding within
structures just to meet your new requirements would be extremely 
undesirable, in my opinion.  If you want object addresses to be
unique, then write your code so that they are unique.  Don't ask the
compiler to put the padding in for you.



#include	<stdio.h>

class A {};

class B : public A
{
public:
	A a;
};

main()
{
	B b;
	A* p1; 
	A* p2;

	p1 = &b;
	p2 = &(b.a);

	if (p1 == p2)
		printf("equal %lX %lX\n", (long)p1, (long)p2);
	else
		printf("unequal %lX %LX\n", (long)p1, (long)p2);

	return 0;
}
Technical Details
Message-ID: <1992Dec16.202800.3398@microsoft.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad
References: <1992Dec14.224035.23715@microsoft.com> <5386@holden.lulea.trab.se>

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: Must derived class reserve space for an empty base class?
Message-ID: <1992Dec16.202800.3398@microsoft.com>
Date: 16 Dec 92 20:28:00 GMT
Organization: Microsoft Corporation
References: <1992Dec14.224035.23715@microsoft.com> <5386@holden.lulea.trab.se>
Lines: 45