home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / cplus / 1989 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.6 KB  |  86 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!stanford.edu!lucid.com!lucid.com!jss
  3. From: jss@lucid.com (Jerry Schwarz)
  4. Subject: Re: pointer comparisons
  5. Message-ID: <1993Jan7.025948.23000@lucid.com>
  6. Sender: usenet@lucid.com
  7. Reply-To: jss@lucid.com (Jerry Schwarz)
  8. Organization: Lucid, Inc.
  9. References: <1993Jan4.200625.5680@lucid.com> <1993Jan5.060332.5262@ucc.su.OZ.AU> <1993Jan5.222300.29535@lucid.com> <1993Jan06.201647.7602@microsoft.com>
  10. Date: Thu, 7 Jan 93 02:59:48 GMT
  11. Lines: 73
  12.  
  13. We seem to be arguing as much about the meaning of terms
  14. and the model that should be used to define the semantics of C++
  15. as we are about what the semantics are or should be.  I don't
  16. think this is a fruitful discussion, so I'm going to take a different
  17. tack and present my point of view solely in terms of code.
  18.  
  19.     struct X { int i ; } ;
  20.     struct D : public X {
  21.         X xInD ;
  22.     } ;
  23.  
  24.     void set(X* p, int n) { p->i = n ; }
  25.  
  26.     void f() {
  27.         D d ;
  28.         X* p1 = &d;
  29.         X* p2 = &d.xInD ;
  30.         set(p1, 1) ;
  31.         set(p2, 2) ;
  32.         d.i ; // must be 1 
  33.         d.xInD.i ; // must be 2 
  34.         p1 == p2 ; // ????
  35.         }
  36.  
  37.  
  38. I'm not sure I can prove the two assertions (d.i is 1 and d.xInD.i is 2)
  39. from the ARM.  I know I can't do it without using phrases (like
  40. distinct object) that I'm trying to avoid in this post.  But I hope
  41. there is no doubt about the assertions.
  42.  
  43. The rest of this posting is my opinion about how C++ ought to
  44. be defined (by x3j16/wg21).
  45.  
  46. I believe that p1==p2 ought to be false (i.e. 0).  I'm not sure
  47. I can prove it from the ARM, but I have what I consider good
  48. justification. Namely, the only way that "set" can operate properly
  49. with regard to d.i and d.xInX.i is for there to be some difference in
  50. the values of its first argument on the two calls. Whatever this difference
  51. is, it ought to be reflected in the result of ==.  If words to force
  52. that result aren't already in the working paper, then I support
  53. a change to the working paper.  Otherwise == on pointers becomes
  54. almost useless and we would have to invent something else
  55. (a library function perhaps) to do a complete comparison of 
  56. pointer values.  
  57.  
  58. If there are any implementations out there that for which p1==p2
  59. might be true in the above example, I'd be interested in hearing
  60. about them. 
  61.  
  62. I'm not going to propose any exact wording here or address the question
  63. of whether words already exist in the ARM because any attempt would
  64. drop me into the terminological tar pit.  But I will say that I don't
  65. think those words should make a distinction between X's that have or
  66. don't have data members, or virtuals, or pure virtuals or anything
  67. else.
  68.  
  69.   -- Jerry Schwarz
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.