GCC aliasing rules: more aggressive than C99?

Paolo Bonzini bonzini@gnu.org
Mon Jan 4 09:51:00 GMT 2010


On 01/03/2010 11:25 PM, Richard Guenther wrote:
>> >    char charray[sizeof(long)] = {...};
>> >    long l = *(long*)charray;  // ok
>
> not correct;)   (the lvalue has to be of character type, yours is of
> type 'long' - the type of the actual object does not matter)

What would be correct instead is

    memcpy ((char *) &l, charray, sizeof(long));

Paolo



More information about the Gcc mailing list