[Bug c/61502] == comparison on "one-past" pointer gives wrong result
joseph at codesourcery dot com
gcc-bugzilla@gcc.gnu.org
Fri Jun 13 22:59:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61502
--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Except within a larger object, I'm not aware of any reason the cases of
two objects following or not following each other in memory must be
mutually exclusive. (If the implementation can track the origins of
bit-patterns and where copies of those bit-patterns have got to, it might
have a compacting garbage collector that relocates objects and changes
what's adjacent to what, for example - I think such implementations are
within the scope of what the C standard is intended to support. Or if
you're concerned about how this changes bit-patterns of pointers, imagine
that a C pointer is a (object key, offset) pair, and that comparison first
converts the C pointer into a hardware address, where it's the mapping
from object keys to hardware addresses that changes as a result of garbage
collection rather than anything about the representation of the pointer.)
So the only way within the C standard you could deduce that two objects
follow each other in memory is that the address of one compares equal to
one past the address of the other - but that does not mean they follow
each other in memory for any other comparison.
An object having a constant address (6.2.4#2) is described non-normatively
in footnote 33 in terms of comparisons of pointers to that object. I
don't think it should be taken to mean comparisons of pointers to
different objects need to have constant results.
More information about the Gcc-bugs
mailing list