home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1154 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  1.8 KB

  1. Path: sparky!uunet!mcsun!sunic!hagbard!loglule!jbn
  2. From: jbn@lulea.trab.se (Johan Bengtsson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <4950@holden.lulea.trab.se>
  6. Date: 11 Sep 92 10:19:57 GMT
  7. References: <1992Sep10.162906.14398@genghis.borland.com>
  8. Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
  9. Lines: 36
  10. X-Newsreader: Tin 1.1 PL4
  11.  
  12. pete@genghis.borland.com (Pete Becker) writes:
  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. :     Not necessarily. The requirement is only that the original pointers can
  23. : be restored, not that their representations as longs be identical.  For 
  24. : example:
  25. :     0x0000:0x0010
  26. :     0x0001:0x0000
  27. : These two addresses refer to the same memory location.  Converting them to
  28. : longs in the most obvious way produces these two values:
  29. :     0x00000010
  30. :     0x00010000
  31.  
  32. But can this really happen, if the rule "pointer arithmetic only
  33. within an array" is adhered to?  Shouldn't all pointers within an
  34. array be based on the same segment?
  35.  
  36. And for memory models that do not have this requirement (the s.c.
  37. "huge" model), pointer comparison should be smart enough anyway, no?
  38.  
  39. -- 
  40. --------------------------------------------------------------------------
  41. | Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
  42. | Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
  43. --------------------------------------------------------------------------
  44.