strict aliasing question

Howard Chu hyc@highlandsun.com
Sun Nov 12 10:33:00 GMT 2006


Dave Korn wrote:
> On 12 November 2006 04:16, Howard Chu wrote:
>
>   
>> Dave Korn wrote:
>>     
>>>>         f = (struct foo *)(void *)buf;
>>>>
>>>>         
>> That's good, but why is it safe?
>>     
>
>
>   Passing through void* means gcc has to assume it could alias anything,
> IIUIC, as a result of the standard allowing implicit void*<=>T* conversions.
>
>   
Ah right, 6.5.16.1 Simple assignment, Constraints...

    one operand is a pointer to an object or incomplete type  and the 
other is a pointer to a qualified or unqualified version of void, and 
the type pointed to by the left has all the qualifiers of the type 
pointed to by the right;

So actually
    f = (void *)buf;
works without complaint.

Thanks for pointing that out.

-- 
  -- Howard Chu
  Chief Architect, Symas Corp.  http://www.symas.com
  Director, Highland Sun        http://highlandsun.com/hyc
  OpenLDAP Core Team            http://www.openldap.org/project/



More information about the Gcc mailing list