GCC aliasing rules: more aggressive than C99?

Joseph S. Myers joseph@codesourcery.com
Tue Jan 5 15:30:00 GMT 2010


On Tue, 5 Jan 2010, Vincent Lefevre wrote:

> On 2010-01-05 10:31:13 +0000, Andrew Haley wrote:
> > "An object shall have its stored value accessed only by an lvalue
> > expression that has one of the following types:
> > 
> > but
> > 
> >  (union u*)&i
> > 
> > is not a legal lvalue expression because the dereference is undefined
> > behaviour.  You may only dereference a pointer as permitted by 6.3.2.3.
> 
> For the same reason, (char *) &i could not be dereferenced, and this
> would break a lot of code!

No, read 6.3.2.3 again.  Specifically, where it says "When a pointer to an 
object is converted to a pointer to a character type, the result points to 
the lowest addressed byte of the object. Successive increments of the 
result, up to the size of the object, yield pointers to the remaining 
bytes of the object.".

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Gcc mailing list