Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-23.2

In this section:
Synopsis

(Required) A generic selection that is not expanded from a macro shall not contain potential side effects in the controlling expression.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found generic selection with potential side effects in controlling expression.

Coding standards
MISRA C:2012 Rule-23.2

(Required) A generic selection that is not expanded from a macro shall not contain potential side effects in the controlling expression.

Code examples

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

#include <stdint.h>

int shared_state;

void example(void) {
  /* Non-compliant */
  int a = _Generic ( ++shared_state, short: 0, default: 1);
} 

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

int shared_state;

void example(void) {
  /* Compliant */
  int a = _Generic ( shared_state, short: 0, default: 1);
}