home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / cplus / 1949 < prev    next >
Encoding:
Text File  |  1993-01-02  |  3.9 KB  |  89 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: pointer comparisons
  5. Message-ID: <9300300.29900@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1992Dec27.050118.1628@lpi.liant.com> <1992Dec30.184614.5551@microsoft.com> <1992Dec31.170223.21637@lpi.liant.com>
  9. Date: Sat, 2 Jan 1993 13:30:07 GMT
  10. Lines: 77
  11.  
  12. pkt@lpi.liant.com (Scott Turner) writes:
  13.  
  14. >(Jim Adcock) writes:
  15. >> "distinct objects" means what?
  16. >It means the objects are not identical.  
  17. >
  18. >I was going to say that the standard for C++ needs to spell out what it
  19. >means for object to be identical in a better way than just by
  20. >     1. An object is a region of storage.
  21. >     2. A definition or a new expression reserves the storage
  22. >        needed by the object.
  23. >These two rules leave things much more loose than necessary when objects
  24. >require no storage.  But note that section 1.3 of the working paper 
  25. >(The C++ Memory Model) says:
  26. >
  27. >    The constructs in a C++ program create, refer to, access, and
  28. >    manipulate objects in memory.  Each object (except bit-fields)
  29. >    occupies one or more contiguous bytes.
  30.  
  31. Let me just interject: what is the motivation for the above (as opposed
  32. to "... occupies zero or more contiguous bytes")?
  33. It seems to me that it is there primarily as an attempt to ensure some
  34. sort of guarantee about pointer comparisons. (Are there any other reasons?)
  35. However, the murkiness of the concepts involved in "object identity" appears
  36. to make it very difficult or impossible to provide such guarantees.
  37.  
  38. If indeed it is the case that the above wording has failed to achieve its
  39. purpose, then there are strong efficiency arguments which suggest that it
  40. should be modified.
  41.  
  42. >I missed this a while back when enumerating the features of the ARM and
  43. >working paper which supported
  44. >> The desired feature is:
  45. >>     Two pointers to the same type, which point to distinct objects
  46. >>     of that type, compare not equal.
  47. >This excerpt from 1.3 gives the general rule I was seeking, because
  48. >objects can be distinguished by the storage reserved for them.
  49. >
  50. >The excerpt may raise a few questions.
  51. >
  52. >    How much freedom does it leave a compiler to optimize away
  53. >    an object's bytes (by application of the "as if" rule, etc.)?
  54. >    I think a good deal of freedom, because the working paper
  55. >    doesn't define the results if a program attempts to refer to
  56. >    or manipulate the bytes of an object.
  57.  
  58. Perhaps, but
  59.     "The _sizeof_ operator yields the size, in bytes, of its operand".
  60. I think that it would be a very brave compiler-writer whose compiler
  61. made it unreliable to write() an object and read() it in again, because
  62.     read(fd, &object, sizeof object);
  63. randomly trashes the bytes past the end of the object.
  64.  
  65. >    Does it govern base class subobjects?  As I understand it,
  66. >    base class subobjects are objects, and hence are covered.
  67.  
  68. Is your understanding based on reading the working paper, or discussion with
  69. members of the committee, or is it your personal judgement of the meaning
  70. of "subobject"? My own metaphysical perspective is that subobjects are
  71. by definition not objects in their own right - that's why virtual functions
  72. work the way they do. If subobjects *were* objects, then there would be
  73. no difference between private inheritance and membership. Thus my own
  74. personal judgement would be that (presuming nothing else is to the contrary)
  75. base class subobjects would not be covered.
  76.  
  77. >    Does it belong in the C++ standard?  I'd say yes, given that
  78. >    compilers will for many practical purposes be able to 
  79. >    optimize away unneeded bytes.
  80.  
  81. I would be inclined to suspect that such opportunities would be
  82. quite rare, given the restrictions mentioned above.
  83.  
  84. -- 
  85. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  86. This .signature virus is a self-referential statement that is true - but 
  87. you will only be able to consistently believe it if you copy it to your own
  88. .signature file!
  89.