[PATCH] C undefined behavior fix
Joseph S. Myers
jsm28@cam.ac.uk
Fri Jan 4 14:02:00 GMT 2002
On Fri, 4 Jan 2002, Linus Torvalds wrote:
> The thing is, pointer expressions outside the area may be "undefined
> behaviour", but the same is NOT true if you cast the thing to an
> unsigned long or similar. At that point it is _implementation_ defined
> what the result is, and gcc has clear guidelines on what the
> int->pointer conversion is.
The GCC implementation defines pointer-integer-pointer conversion to be
undefined if you go outside the object. See the mainline manual:
http://gcc.gnu.org/onlinedocs/gcc/Arrays-and-pointers-implementation.html
This is related to the general questions about provenance of pointer
values discussed in DR#260.
http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/dr_260.htm
--
Joseph S. Myers
jsm28@cam.ac.uk
More information about the Gcc
mailing list