home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1768 < prev    next >
Encoding:
Internet Message Format  |  1992-12-12  |  2.4 KB

  1. Path: sparky!uunet!enterpoop.mit.edu!eru.mt.luth.se!hagbard!loglule!jbn
  2. From: jbn@lulea.trab.se (Johan Bengtsson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Must derived class reserve space for an empty base class?
  5. Message-ID: <5367@miramon.lulea.trab.se>
  6. Date: 12 Dec 92 17:23:39 GMT
  7. References: <1992Dec10.194445.24332@microsoft.com>
  8. Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
  9. Lines: 46
  10. X-Newsreader: TIN [version 1.1 + PL8]
  11.  
  12. Jim Adcock (jimad@microsoft.com) wrote:
  13. : jbn@lulea.trab.se (Johan Bengtsson) writes:
  14. : |Jim Adcock (jimad@microsoft.com) wrote:
  15. : |: steve@taumet.com (Steve Clamage) writes:
  16. : |: |jimad@microsoft.com (Jim Adcock) writes:
  17. : |: ||In "C" common implementation would make &g and &g.e identical,
  18. : |: ||contradicting your assumptions.
  19. : |: |
  20. : |: |I don't this can happen in C, since you can't define a zero-sized object
  21. : |: |or type.
  22. [...]
  23. : |: |On that basis, C compatibility would not seem to be an issue.
  24. : |
  25. : |: But the struct need not be empty for &g and &g.e to be identical.
  26. : |
  27. : |But it must, at least to produce two pointers of the same type that
  28. : |compare equal.  Also, "g" and "g.e" must share a common superclass
  29. : |for this to happen (within the type system).
  30.  
  31. : Below find legal C and C++ programs with non-empty structs where "g" and
  32. : "g.e" compare equal.
  33.  
  34. Jim, we have obviously not been clear enough (me and Steve).  Yes,
  35. the address of an object and its first member _cast to void*_ may
  36. compare equal, so code handling void pointers must not assume
  37. this kind of pointer distinctness.  However, neither "&g" nor "&g.e"
  38. is of type void*.
  39.  
  40. [ Questionable C example involving compiler-generated conversion
  41.   to void* deleted ]
  42.  
  43. The fact that applying the adress operator (&) to a reference yields
  44. a pointer to the referred-to object is irrelevant, since a reference
  45. is just an alias for the referred-to object.  You cannot obtain
  46. a pointer to a reference (as you already know).  This should not cause
  47. any trouble.
  48.  
  49. [ C++ example involving a reference data member that refers to *this deleted ]
  50.  
  51. Perhaps with this clarification you can finally agree with us?
  52.  
  53. -- 
  54. --------------------------------------------------------------------------
  55. | Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
  56. | Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
  57. --------------------------------------------------------------------------
  58.