GCC aliasing rules: more aggressive than C99?
Andrew Haley
aph@redhat.com
Sun Jan 3 18:39:00 GMT 2010
On 01/03/2010 12:52 PM, Andreas Schwab wrote:
> Florian Weimer <fw@deneb.enyo.de> writes:
>
>> * Joshua Haberman:
>>
>>> To me this allows the following:
>>>
>>> int i;
>>> union u { int x; } *pu = (union u*)&i;
>>> printf("%d\n", pu->x);
>>
>> I think the cast on the secodn line is undefined,
>
> Only if union u has stricter alignment requirements than int;
> otherwise you are guaranteed to get back the original pointer when
> casting back to int*.
Right, but it's also important to point out that you can't dereference
that pointer without undefined behaviour: all you can do is cast it
back to an int*.
Andrew.
More information about the Gcc
mailing list