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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Pointer Comparisons
  5. Message-ID: <1992Dec23.172735.15352@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec20.000341.6417@ucc.su.OZ.AU> <5451@holden.lulea.trab.se>
  10. Date: Wed, 23 Dec 1992 17:27:35 GMT
  11. Lines: 138
  12.  
  13. In article <5451@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  14. >John MAX Skaller (maxtal@extro.ucc.su.OZ.AU) wrote:
  15. >
  16. >:   On Pointer Comparisons
  17. >:   ----------------------
  18. [..]
  19. >:    Allocations by 'new' of empty classes will then require at least one
  20. >:    byte of address space be wasted, otherwise
  21. >[...]
  22. >:    Inclusion of an empty class in a structure must also have this
  23. >:    property,[...]
  24. >
  25. >==>    Only if adjacent to another member with which it has a common
  26. >    base class.
  27.  
  28.     Can you have the size different depending ... Yes,
  29. Ok, the size could be zero, and the position of the next object
  30. might be adjusted if required and not otherwise.
  31.  
  32. >
  33. >: Alternative.
  34. >
  35. >:    The alternative rule allows an exception if the classes are empty,
  36. >:    empty meaning either no data members, or better, no data members
  37. >:    and no virtual functions.
  38. >
  39. >==>    "no virtual functions" is perhaps too restrictive, since that
  40.  
  41.     Yes.
  42.  
  43. >    I think "no data members" must be enough to void all
  44. >    guarantees on pointer distinctness (in this alternative
  45. >    to rule (1)).
  46. >    I think the alternate rule (1) must be
  47. >
  48. >    "You can't rely on pointer equivalence for classes that have
  49. >    no data members"
  50.  
  51.     Fine.
  52. >
  53. >    disqualifying among others many abstract base classes (I know
  54. >    you John like MI mix-ins, many of those should be affected too).
  55.  
  56.     Well, that just means you want rule(1) and not rule(1A).
  57. There has been disagreement on this so I didnt want to preempt the
  58. outcome here by making a decision. But likely rule 1 will do
  59. because ARM requires non-zero length objects doesnt it?
  60. >    
  61. >[ definition of "domestic" pointers deleted ]
  62.  
  63.     I think you mean "definition" of domestic pointers deleted :-)
  64.  
  65. >
  66. >:    Two void* compare equal if they were derived from the two
  67. >:    valid domestic pointers that compare equal, and those
  68. >:    pointer values remain valid.
  69. >
  70. >==>    Two void* should also be allowed to compare equal in
  71.  
  72.     you must mean "required" not "allowed" surely?
  73.  
  74. >    cases where they are not derived from two domestic
  75. >    pointers that compare equal, i.e.
  76. >
  77. >    p1==p2  ==>  (void*)p1==(void*)p2,
  78.  
  79.     Maybe. And maybe this rule is totally wrong!
  80. Consider
  81.  
  82.     class A {} class B : A {} 
  83.     B* b=new B;
  84.     A* a=b;
  85.     a==b; // YES after implicit conversion of b to an A
  86.     (void*)a == (void*)b; // NO, they point different places
  87.  
  88. So I think unless I'm wrong here and right before this rule has to
  89. be withdrawn :-(
  90.     
  91. >
  92. >    but not the other way around.  The reverse should only hold
  93. >    if (p1 == p2) is defined, assuming equality comparison
  94. >    is only defined if p1 and p2 are of the same type, or share
  95. >    a common base class.
  96.  
  97.     I assume you can only compare pointers of exactly the same
  98. type. All other comparisons must convert one of the pointers first.
  99.  
  100. >
  101. >    Also note that the common base class of p1 and p2 must not
  102. >    be an empty class (if the alternative rule (1) is adopted).
  103. >
  104. >: Comment
  105. >
  106. >:    The desired equivalence
  107. >
  108. >:    a==b <==> a,b refer to the same object
  109. >:    a!=b <==> a,b refer to different objects
  110. >
  111. >:    is subject to the 3 constraints:
  112. >
  113. >:    a) nonempty class (if rule 1 alternative is taken)
  114. >:    b) validity (continued existence of the object pointed to)
  115. >:    c) domesticity (exclusion of mangling and foreign suppliers)
  116. >
  117. >==>    I like the analysis, although I think constraint a) should
  118. >    be removed, since all classes with no data members must be
  119. >    considered "empty".
  120.  
  121. If "empty" classes are zero length, you need the caveat, otherwise
  122. you dont.
  123.  
  124. I really dont know if this sort of thing is viable for the Standard.
  125. The whole of this was to allow certain types of code to be
  126. non-strictly conforming without being non-conforming.
  127.  
  128. In particular, it might perhaps *allow* vendor supplied
  129. standard routines to muck with pointers without making
  130. programs written using these features non-conforming.
  131. (E.g. Borland and most DOS systems allow construction
  132. and manipulation of pointers with language extensions.).
  133.  
  134. But I think really all bets might be off. You would
  135. have to replace /pointer/ with /domestic pointer/
  136. throughout most of the standard, eg
  137.  
  138.     x->print(); // x has to be domestic
  139.  
  140. and what it might ome down to is that all pointers
  141. are assumed domestic in the standard anyhow .. so there
  142. is nothing really to say. Sigh. I'm learning.
  143. Never thought comparing two pointers would be so
  144. hard to understand .. I do it now and then with no great qualms :-)
  145.  
  146. -- 
  147. ;----------------------------------------------------------------------
  148.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  149.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  150. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  151.