Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2008-5-3-1

In this section:
Synopsis

(Required) Each operand of the ! operator, the logical && or the logical || operators shall have type bool.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Operands of the logical operators (&&, ||, and !) were found that are not of type bool. This check is identical to MISRAC2004-12.6_a.

Coding standards
MISRA C:2004 12.6

(Advisory) The operands of logical operators (&&, ||, and !) should be effectively boolean. Expressions that are effectively boolean should not be used as operands to operators other than (&&, ||, !, =, ==, !=, and ?:).

Code examples

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

void example(void) {

	int d, c, b, a;

	d = ( c & a ) && b;

}

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

typedef char boolean_t; /* Compliant: Boolean-by-enforcement */

void example(void)
{
  boolean_t d;
  boolean_t c = 1;
  boolean_t b = 0;
  boolean_t a = 1;

  d = ( c && a ) && b;
}