home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1840 < prev    next >
Encoding:
Text File  |  1992-12-20  |  3.5 KB  |  103 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: Pointer comparisons
  5. Message-ID: <BzG0C8.I2@frumious.uucp>
  6. Date: Fri, 18 Dec 1992 06:50:32 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp> <1992Dec17.151642.9954@bcrka451.bnr.ca>
  9. Organization: None
  10. Lines: 91
  11.  
  12. sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
  13. |In article <BzDs2x.wA@frumious.uucp> uunet.ca!frumious!pat writes:
  14. |>
  15. |>   Two pointers to the same object compare equal.  If two pointers
  16. |
  17. |...but nowhere do I see a statement that (p == q) ==> p and q point
  18. |to the same object, even if p and q are the same type.
  19.  
  20. Nor do I.  But I think I once saw a discussion of this, and someone
  21. said this would be changed in a future version of the draft.
  22. (My memory of this is vague, though, so I may be imagining things.)
  23.  
  24.  
  25. |Is it possible for two objects of the same type to be in different
  26. |segments and compare equal?
  27.  
  28. I would hope not, if they are different objects.  But the draft
  29. seems to allow it.
  30.  
  31.  
  32. |>Would something
  33. |>similar to the following be reasonable?  (It would clearly need
  34. |>much more careful wording and attention to details.)
  35. |>
  36. |>2) In general, the results of the comparisons need not have anything
  37. |>   to do with the objects to which the pointers point.  For example,
  38. |>   it is possible that p and q point to the same object, but p != q.
  39. |>   (But see below.)
  40. |
  41. |Note that this provides your counterexample for    
  42. |
  43. |   (p == q) <==> (ptrcmp(p,q) == 0)
  44.  
  45. Yes, although this is under my proposal, not under the existing draft.
  46.  
  47.  
  48. |>3) The relational operators define a total ordering on the set of
  49. |>   pointers of each type.  (All the normal rules, including
  50. |>   transitivity.)
  51. |
  52. |Is this possible?  Mightn't some objects of one type be in one segment
  53. |and some in another?  (Perhaps I should say "practical", not "possible").
  54.  
  55. I think it's possible, by doing bitwise comparisons of the pointers
  56. (ignoring padding, if any).  Remember that so far, the comparisons
  57. don't have to be related in any way to the objects pointed to;
  58. I am _not_ asking for a total order on the address space.
  59.  
  60.  
  61. |>4) If two pointers p and q (of the same type) are obtained through
  62. |>   sequences of "normal" operations, then
  63. |>
  64. |>      p == q   <==>   p and q point to the same object
  65. |
  66. |I could not find this statement in the current wording.  Is there a 
  67. |reason why the current wording is weaker than this?
  68.  
  69. I don't know.  The C standard requires both directions of the
  70. implication.  I'm not sure if the concept "p and q point to
  71. the same object" is clearly defined anywhere.
  72.  
  73.  
  74. |What do you mean by "normal" operations?
  75. |What are examples of "abnormal" operations?
  76.  
  77. These were described lower down in my previous posting.
  78. "Normal" operations are the ones whose semantics are defined
  79. by the standard; "abnormal" ones are the others.
  80.  
  81.  
  82. |>One might add a library function sameObject(p,q) which would
  83. |>indicate whether p and q point to the same object, no matter
  84. |>how p and q were obtained.
  85. |
  86. |Is this necessary if we have ptrcmp?  If we like the name ptrcmp, shouldn't
  87. |we like the name ptreq?
  88.  
  89. My idea with the above description of the operators was that ptrcmp
  90. would be unnecessary; the operators could be used instead.
  91.  
  92.  
  93. |Also, if p = (Base *)q, should sameObject(p,q) be 1?
  94.  
  95. Yes.  And also p == q should be 1.  But note that before doing
  96. either comparison, q is converted to a Base* so that one has
  97. two pointers of the same type.
  98.  
  99. -- 
  100. Patrick Smith
  101. uunet.ca!frumious!pat
  102. pat%frumious.uucp@uunet.ca
  103.