Let's ask the converse question:
- What types other than an integer type could a bit field be?
Let's review the options:
void
: not a value — wouldn't work.- Pointers: but pointers on a machine are fixed size; you can't use 13 bits of a pointer and expect it to mean anything.
- Structures, unions: but then you aren't dealing with simple fields.
- That leaves
float
ordouble
, but those are carefully designed formats and you can't simply use 13 bits out of adouble
(orfloat
) and expect it to mean anything.
So, after you've gone through the options, you are left with the various types of integer: char
, short
, int
, long
, long long
(in signed and unsigned forms), and _Bool
. Of these options, the standard specifies that you can use _Bool
, unsigned int
, signed int
and 'plain' int
:
ISO/IEC 9899:2011 §6.7.2.1 Structure and union type specifiers
¶5 A bit-field shall have a type that is a qualified or unqualified version of
_Bool
,signed int
,unsigned int
, or some other implementation-defined type. It is implementation-defined whether atomic types are permitted.
The behaviour of 'plain' int
is implementation defined: it may be signed or unsigned (roughly like 'plain' char
can be signed or unsigned). So, the comment by jxh is correct; I was careless quoting too many types (but I've rephrased things so that it isn't so misleading).
Note that most of the behaviour of bit-fields is implementation defined; beyond the notation, there is very little that is specified by the standard.