Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-20.6_b

In this section:
Synopsis

(Required) Tokens that look like a preprocessing directive shall not occur within a macro argument.

Enabled by default

Yes

Severity/Certainty

High/Low

highlow.png
Full description

A preprocessing directive was found within a macro argument. This check is identical to CERT-PRE32-C_b, MISRAC++2023-19.3.5_b.

Coding standards
CERT PRE32-C

Do not use preprocessor directives in invocations of function-like macros

MISRA C:2012 Rule-20.6

(Required) Tokens that look like a preprocessing directive shall not occur within a macro argument

MISRA C++ 2023 19.3.5

(Required) Tokens that look like a preprocessing directive shall not occur within a macro argument

Code examples

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

#define memcpy(a,b,c) _myfn(a,b,c)

void func(const char *src) {
  /* Validate the source string; calculate size */
  char *dest;
  /* malloc() destination string */
  memcpy(dest, src,
#ifdef PLATFORM1
      12
#else
      24
#endif
      );
  /* ... */
}

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

#define memcpy(a,b,c) _myfn(a,b,c)

void func(const char *src) {
  /* Validate the source string; calculate size */
  char *dest;
  /* malloc() destination string */ 
  #ifdef PLATFORM1
    memcpy(dest, src, 12);
  #else
    memcpy(dest, src, 24);
  #endif
  /* ... */
}