home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1145 < prev    next >
Encoding:
Text File  |  1992-09-09  |  1.6 KB  |  42 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: Zero-length structures and pointer comparisons
  5. Message-ID: <9225414.15952@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se>
  9. Date: Thu, 10 Sep 1992 04:37:29 GMT
  10. Lines: 30
  11.  
  12. jbn@lulea.trab.se (Johan Bengtsson) writes:
  13.  
  14. >If sizeof(long) >= sizeof(void*), then you should be able to
  15. >test like this:
  16. >
  17. >assert( (long)p1 != (long)p2 );
  18. >
  19. >since a pointer stored in an integer variable must keep all information
  20. >needed to restore the pointer (if the integer type is large enough).
  21.  
  22. I don't think that this is the case.
  23.  
  24. If the integer variable is *larger* than the pointer, then some of the
  25. bits in the integer need not be used when converting from integer to pointer.
  26. I do not see any restriction in the reference manual that would require
  27. the opposite conversion to initialize those bits.
  28. This would then mean that (long) p1 != (long) p2 might return true even
  29. when p1 == p2, because the uninitialized padding bits might be different.
  30.  
  31. [This means that ((long) p1) may behave "non-deterministically", although
  32. ((void *)(long)p1) is guaranteed to evaluate to p1 provided that "long"
  33. is sufficiently large.]
  34.  
  35. Is that all correct?
  36.  
  37. -- 
  38. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  39. This .signature virus is a self-referential statement that is true - but 
  40. you will only be able to consistently believe it if you copy it to your own
  41. .signature file!
  42.