This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Clarification on Gcc's strict aliasing rules
On 11/12/2010 03:37 PM, Segher Boessenkool wrote:
>>>>> int f() {
>>>>> union a_union t;
>>>>> int* ip;
>>>>> t.d = 3.0;
>>>>> ip = &t.i;
>>>>> return *ip;
>>>>> }
>>>>>
>>>>> could you tell me what the effective type of 't.i' object ?
>>>>
>>>> int, if you can say that object exists at all: it does not have a
>>>> stored
>>>> value. The stored value of t is a double with value 3.0 . You can
>>>> take its address and access it via that as "double" (or "char"), or you
>>>> can access it as the union it is. You can not access it as "int".
>>>
>>> BTW, does your reasoning rely on the C standard ?
>>
>> It's a gcc extension. 5.25, Cast to a Union Type
>
> There is no cast to union here. Also, casts to union do not provide
> lvalues, so they cannot be used to access objects.
>
> This code has undefined behaviour both in C99 and GNU99 modes.
Sorry, there is no cast, and that reference is misleading.
Andrew.