Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2023-8.14.1

In this section:
Synopsis

(Advisory) The right-hand operand of a logical && or || operator should not contain persistent side effects

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

There are right-hand operands of && or || operators that contain side effects. This check is identical to MISRAC++2008-5-14-1, MISRAC2004-12.4, MISRAC2012-Rule-13.5.

Coding standards
CWE 768

Incorrect Short Circuit Evaluation

MISRA C:2004 12.4

(Required) The right-hand operand of a logical && or || operator shall not contain side effects.

MISRA C:2012 Rule-13.5

(Required) The right hand operand of a logical && or || operator shall not contain persistent side effects

MISRA C++ 2008 5-14-1

(Required) The right hand operand of a logical && or || operator shall not contain side effects.

Code examples

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

#include <stdlib.h>

void example(void) {
	int i;
	int size = rand() && i++;
}

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

#include <stdlib.h>

void example(void) {
	int i;
	int size = rand() && i;
}