Re: Clarification on Gcc's strict aliasing rules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>> 	  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.


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux