Regarding the size of the type that contains bit-fields, the standard says (C11 6.7.2.1 p11):
An implementation may allocate any addressable storage unit large enough to hold a bit-field.
Since this is a union
, and all of the members in the union only use no more than 3 bits from an unsigned int
, the size of the union
would be at least the size if char
, plus padding as required by your system (if any). On many systems it will pad out each unit to the size of the type the bit-field is taken against, so in this case I would expect the size of the union
to be the same as the size of an unsigned int
(although that may have happened due to normal union
padding requirements anyway).
The 0
sized bit-field is a red-herring in a union
, but it has special meaning in a struct
(C11 6.7.2.1 p12):
A bit-field declaration with no declarator, but only a colon and a width, indicates an
unnamed bit-field. 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.
So, if your union
was a struct
instead:
struct d
{
unsigned int a:1;
unsigned int b:3;
unsigned :0;
unsigned int d:1;
unsigned int e:1;
};
Then the size of this struct
would be at least 2 char
s (plus any other padding if required). Most of the time, it would actually come out to the size of 2 unsigned int
s.