Re: Clarification on Gcc's strict aliasing rules

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

 



On 11/12/2010 03:21 PM, Francis Moreau wrote:
> Andrew Haley <aph@xxxxxxxxxx> writes:
> 
>> On 11/12/2010 02:55 PM, Francis Moreau wrote:
>>> "Segher Boessenkool" <segher@xxxxxxxxxxxxxxxxxxx> writes:
>>>
>>> [...]
>>
>>>
>>>>>
>>>>> Looking again at the second example:
>>>>>
>>>>> 	  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
> 
> How can it be related with the existence of an union member ?

I don't understand your question.  Rather than attempt to answer,
I'll ask you to rephrase your question.

It's clear that in an object of type

          union a_union {
            int i;
            double d;
          };

the effective type of i is int.

Andrew.


[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