Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Rule-6.2

In this section:
Synopsis

(Required) Single-bit named bitfields shall not be of a signed type.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

Signed single-bit bitfields (excluding anonymous fields) were found. This check is identical to STRUCT-signed-bit, MISRAC2004-6.5, MISRAC++2008-9-6-4, MISRAC++2023-12.2.3.

Coding standards
MISRA C:2004 6.5

(Required) Bitfields of signed type shall be at least 2 bits long.

MISRA C++ 2008 9-6-4

(Required) Named bit-fields with signed integer type shall have a length of more than one bit.

MISRA C++ 2023 12.2.3

(Required) A named bit-field with signed integer type shall not have a length of one bit

Code examples

The following code example fails the check and will give a warning:

struct S
{
  signed int a : 1; // Non-compliant
};

The following code example passes the check and will not give a warning about this issue:

struct S
{
  signed int b : 2;
  signed int   : 0;
  signed int   : 1;
  signed int   : 2;
};