Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-23.7

In this section:
Synopsis

(Advisory) A generic selection that is expanded from a macro should evaluate its argument only once.

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found generic selection evaluating argument not exactly once.

Coding standards
MISRA C:2012 Rule-23.7

(Advisory) A generic selection that is expanded from a macro should evaluate its argument only once.

Code examples

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

/* Non-compliant */
#define gfun1(X) _Generic((X) \
 , int     : funi (X) \
 , float   : funf (X) \
 , default : default_result )

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

/* Compliant */
#define gfun2(X) (_Generic((X) \
 , int     : funi \
 , float   : funf ) (X))