Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2012-Rule-23.8

In this section:
Synopsis

(Required) A default association shall appear as either the first or the last association of a generic selection.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found generic selection with default association not first or last.

Coding standards
MISRA C:2012 Rule-23.8

(Required) A default association shall appear as either the first or the last association of a generic selection.

Code examples

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

#include <math.h>

/* Non-compliant - default is not first or last association */
#define sqrtF(X) ( _Generic((X) \
 , float : sqrtf \
 , default : sqrt \
 , long double: sqrtl) (X) )

void example(void)
{
  float b = sqrtF(3.0f);
}

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

#include <math.h>

/* Compliant - default is first association */
#define sqrtP(X) ( _Generic((X) \
 , default : sqrt \
 , float : sqrtf ) (X) )

void example(void)
{
  float f1 = sqrtP(3.0f);
}