[previous] 3665 [next] Unnamed bit-field consisting of a single bit declared with a signed type.
Arrays, structures, unions and bit-fields REFERENCE - ISO:C90-6.5.2.1 Structure and Union Specifiers - Semantics

A signed bit-field consisting of a single bit is only able to represent the values -1 and 0. This is seldom useful ! It cannot even represent the number 1.

Unnamed bit-fields are only useful for padding and their contents are irrelevant. It is therefore immaterial whether they are defined with signed or unsigned characteristics. Message 3665 is provided only to address the strict letter of the requirements of MISRA-C.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 3660, 3665, 0634, 2850 --*/
/**************************************
 * OPTIONS: -bits+
 *************************************/

struct mysignedbit              /* Message 0634 */
{
    signed int b1:1;            /* Message 3660 */
    signed int   :1;            /* Message 3665 */
    int        b2:1;            /* Message 3660 */
    int          :1;            /* Message 3665 */
};
extern void foo(void)
{
    struct mysignedbit b;
    b.b1 =  0;                  /* OK */
    b.b1 = -1;                  /* OK */
    b.b1 =  1;                  /* Message 2850 - value "1" cannot be represented ! */
}


MISRA C:2012 Rules applicable to message 3665:

Rule-6.2  (Required) Single-bit named bit fields shall not be of a signed type


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents