Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor edit

The arguments to a macro should must not include preprocessor directives, such as #define, #ifdef, and #include. Doing so is undefined behavior, according to subclause 6.10.3, paragraph 11, of the C Standard [ISO/IEC 9899:2011]:

...

Code Block
bgColor#FFCCCC
langc
#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
  );
  /* ... */
);

...

Code Block
bgColor#ccccff
langc
#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
  /* ... */
}

Risk Assessment

Using Including preprocessor directives inside in macro arguments is undefined behavior.

...