Bit-field

Declares a class data member with explicit size, in bits. Adjacent bit-field members may (or may not) be packed to share and straddle the individual bytes.

# Notes

The following properties of bit-fields are implementation-defined:

In the C programming language, the width of a bit-field cannot exceed the width of the underlying type, and whether int bit-fields that are not explicitly signed or unsigned are signed or unsigned is implementation-defined. For example, int b : 3; may have the range of values [0,7] or [-4,3] in C, but only the latter choice is allowed in C++.

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 324C++98it was unspecified whether the return valueof an assignment to a bit-field is a bit-fieldadded bit-field specifications foroperators which may return lvalues
CWG 739C++98signedness of bit-fields that are neither declaredsigned nor unsigned were implementation-definedconsistent with underlying types
CWG 2229C++98unnamed bit-fields could be declared with a cv-qualified typeprohibited
CWG 2511C++98cv-qualifications were not allowed in bit-field typesbit-fields can have cv-qualifiedenumeration types

# See also