Bit-fields can be used to allow flags or other integer values with small ranges to be packed together to save storage space.
It is implementation - defined whether the specifier int
designates the same type as signed int
or the same type as unsigned int
for bit-fields. According to C99 [ISO/IEC 9899:1999], C integer promotions also require that "If if an int
can represent all values of the original type, the value is converted to an int
; otherwise, it is converted to an unsigned int
."
...
Bit-field types other than _Bool
, int
, signed int
, and unsigned int
are implementation - defined. They still obey the integer promotions quoted above when the specified width is at least as narrow as CHAR_BIT*sizeof(int)
, but wider bit-fields are not portable.
...