Skip to main content

IAR Embedded Workbench for RH850 3.20.x

CERT-PRE32-C_a

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.

Coding standards
CERT PRE32-C

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

Code examples

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

#include <string.h>

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:

#include <string.h>

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
  /* ... */
}