Article View: comp.std.c++
Article #131Re: Zero-length structures and pointer comparisons
From: Pete Becker
Date: Thu, 10 Sep 1992 16:29
Date: Thu, 10 Sep 1992 16:29
33 lines
1477 bytes
1477 bytes
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 The trick on segmented architectures is to always normalize the pointers before comparing. The first pointer above isn't normalized, because it has an offset greater than 15. The second one is normalized. Comparisons between normalized pointers are always valid. -- Pete
Technical Details
Message-ID:
<1992Sep10.162906.14398@genghis.borland.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!decwrl!borland.com!peteReferences:
<9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!borland.com!pete From: pete@genghis.borland.com (Pete Becker) Subject: Re: Zero-length structures and pointer comparisons Message-ID: <1992Sep10.162906.14398@genghis.borland.com> Originator: pete@genghis.borland.com Sender: news@borland.com (News Admin) Organization: Borland International References: <9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se> Date: Thu, 10 Sep 1992 16:29:06 GMT Lines: 35