From 3895698894845106688
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e94695845965b249
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-09-10 23:04:38 PST
Path: 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

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  |
--------------------------------------------------------------------------


