Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2012-Rule-23.1

In this section:
Synopsis

(Advisory) A generic selection should only be expanded from a macro.

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found generic selection not in a macro.

Coding standards
MISRA C:2012 Rule-23.1

(Advisory) A generic selection should only be expanded from a macro.

Code examples

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

#include <stdint.h>

typedef float float32_t;

void example(void) {
  int32_t x = 0;
  /* Non-compliant - not a macro */
  int32_t y = _Generic( x
  , int32_t : 1
  , float32_t : 2 );
}

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

#include <stdint.h>

typedef float float32_t;

  /* Compliant - used to implement a generic function */
#define arith(X) ( _Generic( (X) \
 , int32_t : handle_int32 \
 , float32_t : handle_float \
 , default : handle_any ) (X) )