home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / cplus / 1886 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.4 KB  |  52 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Pointer comparisons
  5. Message-ID: <1992Dec19.001851.22116@microsoft.com>
  6. Date: 19 Dec 92 00:18:51 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp> <1992Dec17.151642.9954@bcrka451.bnr.ca>
  9. Lines: 41
  10.  
  11. In article <1992Dec17.151642.9954@bcrka451.bnr.ca> sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
  12. |>4) If two pointers p and q (of the same type) are obtained through
  13. |>   sequences of "normal" operations, then
  14. |>
  15. |>      p == q   <==>   p and q point to the same object
  16. |
  17. |I could not find this statement in the current wording.  Is there a 
  18. |reason why the current wording is weaker than this?
  19.  
  20. Again, a simple counterexample is as follows:
  21.  
  22. #include <stdio.h>
  23.  
  24. class A {};
  25.  
  26. class B : public A
  27. {
  28. public:
  29.     A a;    
  30. };
  31.  
  32. main()
  33. {
  34.     B b;
  35.  
  36.     A* pb = &b;
  37.     A* pa = &(b.a);
  38.  
  39.     if (pb == pa)
  40.         printf("equality of two legal ptrs of the same type pointing"
  41.         "at different objects");
  42.  
  43.     return 0;
  44. }
  45.  
  46. Again, my claim is that this is perfectly legal C++ code, which is commonly
  47. implemented in some C++ compilers such that the equality test does
  48. test true.  On the contrary, for the test to not prove true would
  49. mean that the empty base class part has to be implemented by the compiler
  50. using gratuitous padding, and gratuitous padding is an anathema to
  51. traditional C/C++ implementation.  
  52.