From -1832734649591293478
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e94695845965b249
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-09-09 14:58:20 PST
Newsgroups: comp.std.c++
Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Subject: Re: Zero-length structures and pointer comparisons
Message-ID: <9225414.15952@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se>
Date: Thu, 10 Sep 1992 04:37:29 GMT
Lines: 30

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

I don't think that this is the case.

If the integer variable is *larger* than the pointer, then some of the
bits in the integer need not be used when converting from integer to pointer.
I do not see any restriction in the reference manual that would require
the opposite conversion to initialize those bits.
This would then mean that (long) p1 != (long) p2 might return true even
when p1 == p2, because the uninitialized padding bits might be different.

[This means that ((long) p1) may behave "non-deterministically", although
((void *)(long)p1) is guaranteed to evaluate to p1 provided that "long"
is sufficiently large.]

Is that all correct?

-- 
Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
This .signature virus is a self-referential statement that is true - but 
you will only be able to consistently believe it if you copy it to your own
.signature file!


