Skip to main content

IAR Embedded Workbench for RL78 5.20

CERT-PRE32-C_b

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

The arguments to a macro must not include preprocessor directives, such as #define, #ifdef, and #include. Doing so results in undefined behavior. This rule also applies to the use of preprocessor directives in arguments to a function where it is unknown whether or not the function is implemented using a macro. This check is identical to MISRAC2012-Rule-20.6_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
  /* ... */
}