Angel Tsankov wrote:
Does the C++ standard define what should happen if the size of int in the
following code cannot accommodate the bit field?
struct bit_fields
{
unsigned int digit:17; // int is 16 bits
};
The excess bits force are used for padding:
[9.6/1] A member-declarator of the form
identifier_opt : constant-expression
specifies a bit-field; its length is set off from the bit-field name by a
colon. The bit-field attribute is not part of the type of the class member.
The constant-expression shall be an integral constant-expression with a
value greater than or equal to zero. The constant-expression may be larger
than the number of bits in the object representation (3.9) of the
bit-field?s type; in such cases the extra bits are used as padding bits and
do not participate in the value representation (3.9) of the bit-field.
[...]
Best
Kai-Uwe Bux