On 2015-03-11 17:39:31 +0100, Jakub Jelinek wrote: > On Wed, Mar 11, 2015 at 05:31:01PM +0100, Vincent Lefevre wrote: > > > (in C only one union member can be active at any time, > > > we as extension allow type punning through unions etc.) > > > > I disagree that it is an extension. The standard does not say > > that "one union member can be active at any time". > > That is not a standard wording, but what I meant is > 6.2.6.1p7 - that when you store some union member other union members take > unspecified values.
Well, the values are unspecified, but the value can sometimes be deduced from what is stored. BTW, the C11 draft I have says: When a value is stored in a member of an object of union type, the bytes of the object representation that do not correspond to that member but do correspond to other members take unspecified values. Note the "that do not correspond to that member but do correspond to other members". This means that on a machine where an int takes 4 bytes, if one has: union { unsigned char a[8]; int b; } u = { .a = { 0 } }; u.b = 1; Then the last 4 bytes of u.a take unspecified values. But the first 4 bytes depend on the representation of the int 1, and if this representation is well-specified by the implementation (e.g. no padding bits...), which can sometimes be deduced, then the first 4 bytes of u.a are known and one can access them via u.a. -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)