Undefined behavior in glibc
Joseph Myers
joseph@codesourcery.com
Fri Feb 5 22:35:00 GMT 2016
On Fri, 5 Feb 2016, Alexander Cherepanov wrote:
> If you take an address of the array itself then you can access any of its
> bytes but I don't think the standard permits you to go back from working with
> chars to working with longs. Roughly speaking, the structure of the object is
> forgotten. While you stay at the beginning of the object you can go back --
> it's a general rule: you can convert unchanged pointers forth and back freely
> (modulo alignment). But if you move from the beginning then you lose this
> freedom. The standard doesn't describe going from an unrelated pointer to char
> to a pointer to an (sub)object.
I think going from the pointer to char back to a pointer to long is valid
in GNU C and in common usage C, provided you never access the same memory
with different non-character types (other than signed/unsigned variations)
in ways that would require a union to do without conversions between
pointer types.
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Libc-alpha
mailing list