25.3.13 Default Bit-field int
Type
The type of a bit-field specified as a plain int
is identical to that of
one defined using unsigned int
. This is quite different from other
objects where the types int
, signed
and signed
int
are synonymous. It is recommended that the signedness of the bit-field
be explicitly stated in all bit-field definitions.
Example
The following shows an example of a structure tag containing bit-fields that are unsigned integers and with the size specified.
struct OUTPUTS {
int direction :1;
int parity :3;
int value :4;
};
Differences
The 8-bit compilers have previously issued a warning if type int
was
used for bit-fields, but would implement the bit-field with an unsigned
int
type.
The 16- and 32-bit compilers have implemented bit-fields defined using
int
as having a signed int
type, unless the option
-funsigned-bitfields
was specified.
Migration to the CCI
Any code that defines a bit-field with the plain int
type should be
reviewed. If the intention was for these to be signed quantities, then the type of these
should be changed to signed int
. In the following example:
struct WAYPT {
int log :3;
int direction :4;
};
the bit-field type should be changed to signed int
, as in:
struct WAYPT {
signed int log :3;
signed int direction :4;
};