Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Rule-23.5

In this section:
Synopsis

(Advisory) A generic selection should not depend on implicit pointer type conversion.

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found generic selection depending on implicit pointer type conversion.

Coding standards
MISRA C:2012 Rule-23.5

(Advisory) A generic selection should not depend on implicit pointer type conversion.

Code examples

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

void handle_cpi (const int *);
void handle_any (void *);

#define handle_pointer(X) ( _Generic ((X) \
 , const int *: handle_cpi \
 , default : handle_any) (X) )

void example(void) {
  int mi;
  /* Non-compliant - default is selected NOT const int * */
  handle_pointer(&mi);
}

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

void handle_cpi (const int *);
void handle_any (void *);

#define handle_pointer(X) ( _Generic ((X) \
 , const int *: handle_cpi \
 , default : handle_any) (X) )

void example(void) {
  const int ci;
  /* Compliant - const int * is selected */
  handle_pointer(&ci);
}