MISRA.BITFIELD.SIGNEDLength of a named signed bit-field is less than 2. MISRA C 2012 Rule 6.2: Single-bit named bit fields shall not be of a signed typeCategory: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 RationaleAccording to the C99 Standard Section 6.2.6.2, a single-bit signed bit-field has a single (one) sign bit and no (zero) value bits. In any representation of integers, 0 value bits cannot specify a meaningful value. A single-bit signed bit-field is therefore unlikely to behave in a useful way and its presence is likely to indicate programmer confusion. Although the C90 Standard does not provide so much detail regarding the representation of types, the same considerations apply as for C99. Note: this rule does not apply to unnamed bit fields as their values cannot be accessed. Signed bit-field has length 1. MISRA-C 2004 Rule 6.5 (required): Bit fields of signed type shall be at least 2 bits longThis rule is also covered by MISRA.BITFIELD.SIGNED.UNNAMED. A signed bit field of 1 bit length is not useful. MISRA-C++ 2008 Rule 9-6-4 (required): Named bit-fields with signed integer type shall have a length of more than one bitRationaleThe values which may be represented by a bit-field of length one may not meet developer expectations. Anonymous signed bit-fields of any length are allowed. Examplestruct S { signed int a : 1; // Non-compliant signed int : 1; // Compliant signed int : 0; // Compliant signed int b : 2; // Compliant signed int : 2; // Compliant }; |