In C it is possible to force a set of bit-fields to start on a new storage unit relative to their predecessors by specifying a zero-width bit field without a name, e.g.
int field1:10;
int :0;
int field2:5; // will be in a new storage unit
Is there defined behaviour for what happens if two consecutive zero-width fields are declared, e.g.:
int field1:10;
int :0;
int :0;
int field2:5; // will be in a new storage unit
In looking at the C90 and C99 specifications I cannot see anything that specifies explicitly whether the additional field is simply ignored, or if it might cause a whole additional storage unit to be set aside.
The C99 standard says (§6.7.2.1):
As a special case, a bit-field structure member with a width of 0 indicates that no further bit-field is to be packed into the unit in which the previous bit-field, if any, was placed.
To my reading that's ambiguous - if you treat :0
as a "virtual" bit-field (albeit not taking any storage) then one could read the above as saying that the next :0
cannot be packed into the same (non-storage) as the previous one.
My compiler does appear to ignore the extra, but I'd like to know if that's actually guaranteed per the specification.