On Wed, 6 Mar 2013, N.M. Maclaren wrote:

> On Mar 6 2013, Andrew Pinski wrote:
> > 
> > Except GCC implements C's unions as allowing to do type punning as an
> > extension and as far as GCC is concerned that is not going to change
> > any time soon.
> > This is a documented exception to the aliasing/type punning rules.
> 
> The problem is that this is worse than type punning, because it also
> allows the preservation of data.  Does the extension guarantee that,
> or would it need a change to at least the documentation?

I don't think the extension guarantees more than type punning as described 
in the footnote added in C99TC3 ("If the member used to access the 
contents of a union object is not the same as the member last used to 
store a value in the object, the appropriate part of the object 
representation of the value is reinterpreted as an object representation 
in the new type as described in 6.2.6 (a process sometimes called "type 
punning"). This might be a trap representation.").

That is, writing to a smaller member might affect bytes of the union 
outside that member (at least, we don't claim to preserve them).

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to