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

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!spool.mu.edu!hri.com!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: Pointer Comparisons
  5. Message-ID: <5451@holden.lulea.trab.se>
  6. Date: 20 Dec 92 21:03:50 GMT
  7. References: <1992Dec20.000341.6417@ucc.su.OZ.AU>
  8. Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
  9. Lines: 101
  10. X-Newsreader: TIN [version 1.1 + PL8]
  11.  
  12. John MAX Skaller (maxtal@extro.ucc.su.OZ.AU) wrote:
  13.  
  14. :   On Pointer Comparisons
  15. :   ----------------------
  16.  
  17. : I propose
  18. [...]
  19.  
  20. : 1) If two pointers of the same type, (other than void*) compare equal,
  21. :    then they may be assumed to refer to the same object, subobject,
  22. :    or component.
  23.  
  24. : Comment.
  25.  
  26. :    Allocations by 'new' of empty classes will then require at least one
  27. :    byte of address space be wasted, otherwise
  28. [...]
  29. :    Inclusion of an empty class in a structure must also have this
  30. :    property,[...]
  31.  
  32. ==>    Only if adjacent to another member with which it has a common
  33.     base class.
  34.  
  35. : Alternative.
  36.  
  37. :    The alternative rule allows an exception if the classes are empty,
  38. :    empty meaning either no data members, or better, no data members
  39. :    and no virtual functions.
  40.  
  41. ==>    "no virtual functions" is perhaps too restrictive, since that
  42.     might unnecessarily preclude implementations that don't use
  43.     the "vtbl" scheme, for example by tagging all pointers with
  44.     the actual type, or using special hardware (e.g. associative memory).
  45.  
  46.     I think "no data members" must be enough to void all
  47.     guarantees on pointer distinctness (in this alternative
  48.     to rule (1)).
  49.  
  50. :    This alternative precludes use of empty classes solely to create
  51. :    unique objects with no operations, but appears to have no other
  52. :    serious consequences. Since nonempty classes can always be
  53. :    used to artificially create unique object identities, this
  54. :    alternative may be viable.
  55.  
  56. ==>    I would agree, but only for "vtbl" like implementations,
  57.     since objects under future implementations may very well need
  58.     zero storage, even if they have virtual functions. Since we
  59.     do not wish to preclude future non-vtbl implementations
  60.     (right?), I do _not_ think this alternate rule is a good one.
  61.  
  62.     I think the alternate rule (1) must be
  63.  
  64.     "You can't rely on pointer equivalence for classes that have
  65.     no data members"
  66.  
  67.     disqualifying among others many abstract base classes (I know
  68.     you John like MI mix-ins, many of those should be affected too).
  69.     
  70. [...]
  71. [ definition of "domestic" pointers deleted ]
  72.  
  73. :    Two void* compare equal if they were derived from the two
  74. :    valid domestic pointers that compare equal, and those
  75. :    pointer values remain valid.
  76.  
  77. ==>    Two void* should also be allowed to compare equal in
  78.     cases where they are not derived from two domestic
  79.     pointers that compare equal, i.e.
  80.  
  81.     p1==p2  ==>  (void*)p1==(void*)p2,
  82.  
  83.     but not the other way around.  The reverse should only hold
  84.     if (p1 == p2) is defined, assuming equality comparison
  85.     is only defined if p1 and p2 are of the same type, or share
  86.     a common base class.
  87.  
  88.     Also note that the common base class of p1 and p2 must not
  89.     be an empty class (if the alternative rule (1) is adopted).
  90.  
  91. : Comment
  92.  
  93. :    The desired equivalence
  94.  
  95. :    a==b <==> a,b refer to the same object
  96. :    a!=b <==> a,b refer to different objects
  97.  
  98. :    is subject to the 3 constraints:
  99.  
  100. :    a) nonempty class (if rule 1 alternative is taken)
  101. :    b) validity (continued existence of the object pointed to)
  102. :    c) domesticity (exclusion of mangling and foreign suppliers)
  103.  
  104. ==>    I like the analysis, although I think constraint a) should
  105.     be removed, since all classes with no data members must be
  106.     considered "empty".
  107.  
  108. -- 
  109. --------------------------------------------------------------------------
  110. | Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
  111. | Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
  112. --------------------------------------------------------------------------
  113.