Most variables in C have a size that is an integral number of bytes. Bit-fields are a part of a structure that don’t necessarily occupy a integral number of bytes; they can any number of bits. Multiple bit-fields can be packed into a single storage unit. They are a part of standard C, but there are many aspects that are implementation defined. They are one of the least portable parts of C.
- type-specifier identifier : size;
Parameter | Description |
——— | ———– |
identifier | The name for this field in the structure |
size | The number of bits to use for this field |
The only portable types for bit-fields are
_Bool. The plain
int type can be used, but the standard says (§6.7.2¶5) … for bit-fields, it is implementation-defined whether the specifier
int designates the same type as
signed int or the same type as
Other integer types may be allowed by a specific implementation, but using them is not portable.