C Language Tutorial:

C Language Bit fields


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;


type-specifiersigned, unsigned, int or _Bool
identifierThe name for this field in the structure
sizeThe number of bits to use for this field


The only portable types for bit-fields are signed, unsigned or _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 unsigned int.

Other integer types may be allowed by a specific implementation, but using them is not portable.

C Language Bit-fields Examples:

Related C Language Tutorial Topics:

Other Tutorial Topics:

This modified content is an extract of the original Stack Overflow Documentation released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow. This topic was created and modified by the Stack Ovedrflow Contributor.