This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc attributes and realloc
Bruce Korb <bkorb@veritas.com> writes:
> Andreas Schwab wrote:
>
>> This is by no means theoretical only. Think of a segmented
>> architecture, where loading an invalid value into a segment register
>> generates a trap.
>
> On such an architecture, is it necessary to load that segment register
> in order to compare a pointer value?
Not necessarily, but the point is that the standard does not forbid
it.
> Does that mean that in order to do a pointer comparison you must
> first cast with (uintptr_t) or similar?
You can always compare pointers to valid objects, at least with == and
!=.
> Even on an segmented architecture it needs to be possible to compare
> pointers. If it were not necessary, why would realloc() docs talk about
> "(possibly moved) block".
The standard actually says "(which may have the same value as a
pointer to the old object)". You can test for a subset of the "same
value" condition by comparing the representation, and on an
implementation where the indeterminate value of a pointer is never a
trap representation you can even use == or !=, but that is not
strictly compliant.
> [[otherwise, your friendly compiler may delete
> code that references your outdated but bitwise identical pointers]].
Such pointers with identical representations would be
indistinguishable from each other, but the only way to find that out
is to compare with memcmp.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, MaxfeldstraÃe 5, 90409 NÃrnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."