home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: 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
-
- 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
-
-
-
-
-
-
-