home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: 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
-
- 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;
- }
-