MISRA.BITFIELD.TYPEType of bit-field is not signed/unsigned integer. MISRA C 2012 Rule 6.1: Bit-fields shall only be declared with an appropriate typeC90 [Undefined 38; Implementation 29], C99 [Implementation J.3.9(1, 2)] Category: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationThe appropriate bit-field types are:
Note: It is permitted to use typedefs to designate an appropriate type. RationaleUsing int is implementation-defined because bit-fields of type int can be either signed or unsigned. The use of enum, short, char or any other type for bit-fields is not permitted in C90 because the behaviour is undefined. In C99, the implementation may define other integer types that are permitted in bit-field declarations. ExampleThe following example is applicable to C90 and to C99 implementations that do not provide any additional bit-field types. It assumes that the int type is 16-bit. typedef unsigned int UINT_16; struct s { unsigned int b1:2; /* Compliant */ int b2:2; /* Non-compliant - plain int not permitted */ UINT_16 b3:2; /* Compliant - typedef designating unsigned int */ signed long b4:2; /* Non-compliant even if long and int are the * same size */ }; Type of bit-field is not signed/unsigned integer. MISRA-C 2004 Rule 2.1 (required): Bit fields shall only be defined to be of type unsigned int or signed int.[Undefined 38; Implementation 29] Using int is implementation defined because bit fields of type int can be either signed or unsigned. The use of enum, short or char types for bit fields is not allowed because the behaviour is undefined. |