home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1818 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.5 KB  |  56 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Must derived class reserve space for an empty base class?
  5. Message-ID: <1992Dec16.202800.3398@microsoft.com>
  6. Date: 16 Dec 92 20:28:00 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Dec14.224035.23715@microsoft.com> <5386@holden.lulea.trab.se>
  9. Lines: 45
  10.  
  11. In article <5386@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  12. |That two non-generic pointers of the same type (possibly converted from
  13. |pointer-to-derived) to different objects or data members should be
  14. |guaranteed to compare unequal.
  15. |
  16. |Please? (:-)
  17.  
  18. Either you are misstating what you think you are stating, or I am 
  19. misunderstanding what you are stating, or else I strongly disagree,
  20. because I would counterclaim that pointer equality in the following
  21. example is a legal and perfectly reasonable, and efficient, implementation.
  22. On the contrary, requiring unnecessary and unexpected padding within
  23. structures just to meet your new requirements would be extremely 
  24. undesirable, in my opinion.  If you want object addresses to be
  25. unique, then write your code so that they are unique.  Don't ask the
  26. compiler to put the padding in for you.
  27.  
  28.  
  29.  
  30. #include    <stdio.h>
  31.  
  32. class A {};
  33.  
  34. class B : public A
  35. {
  36. public:
  37.     A a;
  38. };
  39.  
  40. main()
  41. {
  42.     B b;
  43.     A* p1; 
  44.     A* p2;
  45.  
  46.     p1 = &b;
  47.     p2 = &(b.a);
  48.  
  49.     if (p1 == p2)
  50.         printf("equal %lX %lX\n", (long)p1, (long)p2);
  51.     else
  52.         printf("unequal %lX %LX\n", (long)p1, (long)p2);
  53.  
  54.     return 0;
  55. }
  56.