Article View: comp.std.c++
Article #141Re: Zero-length structures and pointer comparisons
From: Johan Bengtsson
Date: Fri, 11 Sep 1992 10:19
Date: Fri, 11 Sep 1992 10:19
36 lines
1842 bytes
1842 bytes
pete@genghis.borland.com (Pete Becker) writes: : In article <4945@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes: : > : >If sizeof(long) >= sizeof(void*), then you should be able to : >test like this: : > : >assert( (long)p1 != (long)p2 ); : > : >since a pointer stored in an integer variable must keep all information : >needed to restore the pointer (if the integer type is large enough). : : Not necessarily. The requirement is only that the original pointers can : be restored, not that their representations as longs be identical. For : example: : : 0x0000:0x0010 : 0x0001:0x0000 : : These two addresses refer to the same memory location. Converting them to : longs in the most obvious way produces these two values: : : 0x00000010 : 0x00010000 But can this really happen, if the rule "pointer arithmetic only within an array" is adhered to? Shouldn't all pointers within an array be based on the same segment? And for memory models that do not have this requirement (the s.c. "huge" model), pointer comparison should be smart enough anyway, no? -- -------------------------------------------------------------------------- | Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden | | Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490 | --------------------------------------------------------------------------
Technical Details
Message-ID:
<4950@holden.lulea.trab.se>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!hagbard!loglule!jbnReferences:
<1992Sep10.162906.14398@genghis.borland.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!hagbard!loglule!jbn From: jbn@lulea.trab.se (Johan Bengtsson) Newsgroups: comp.std.c++ Subject: Re: Zero-length structures and pointer comparisons Message-ID: <4950@holden.lulea.trab.se> Date: 11 Sep 92 10:19:57 GMT References: <1992Sep10.162906.14398@genghis.borland.com> Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden Lines: 36 X-Newsreader: Tin 1.1 PL4