home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1148 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.4 KB  |  48 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!decwrl!borland.com!pete
  3. From: pete@genghis.borland.com (Pete Becker)
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <1992Sep10.162906.14398@genghis.borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se>
  10. Date: Thu, 10 Sep 1992 16:29:06 GMT
  11. Lines: 35
  12.  
  13. In article <4945@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  14. >
  15. >If sizeof(long) >= sizeof(void*), then you should be able to
  16. >test like this:
  17. >
  18. >assert( (long)p1 != (long)p2 );
  19. >
  20. >since a pointer stored in an integer variable must keep all information
  21. >needed to restore the pointer (if the integer type is large enough).
  22. >
  23.  
  24.     Not necessarily. The requirement is only that the original pointers can
  25. be restored, not that their representations as longs be identical.  For 
  26. example:
  27.  
  28.     0x0000:0x0010
  29.     0x0001:0x0000
  30.  
  31. These two addresses refer to the same memory location.  Converting them to
  32. longs in the most obvious way produces these two values:
  33.  
  34.     0x00000010
  35.     0x00010000
  36.  
  37. The trick on segmented architectures is to always normalize the pointers before
  38. comparing. The first pointer above isn't normalized, because it has an offset
  39. greater than 15.  The second one is normalized. Comparisons between normalized
  40. pointers are always valid.
  41.     -- Pete
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.