Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2669. MISRA. Tokens that look like...
menu mobile close menu
Additional information
toggle menu Contents

V2669. MISRA. Tokens that look like a preprocessing directive should not occur within a macro argument.

Feb 05 2026

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.

This diagnostic rule is relevant only for C.

A token that looks like a preprocessing directive should not be used as a macro argument. Using preprocessing directives as macro arguments results in undefined behavior.

Look at the example:

#include <stdio.h

#define PRINT(arg) printf("%s", #arg)

int main(int argc, char *argv[])
{
  PRINT(
    #ifndef FLAG
      My program prints: hello.
    #else
      My program prints: world.
    #endif 
  );
}

Depending on whether the FLAG macro is defined, the developer expects the program to print either My program prints: hello or My program prints: world to stdout. Because the behavior is undefined, the compiler can do anything in this situation.

If a program is compiled using GCC or Clang without defining the FLAG macro, the result will be one of the expected options:

My program prints: hello.

However, a program compiled using MSVC will print an unexpected result:

#ifndef FLAG My program prints: hello. #else My program prints: world. #endif

The fixed code:

#include <stdio.h>

#define PRINT(arg) printf("%s", #arg)

int main(int argc, char *argv[])
{
#ifndef FLAG
  PRINT(My program prints: hello.);
#else
  PRINT(My program prints: world.);
#endif 
}

Now all programs compiled using different compilers print the same text depending on the FLAG macro definition.

This diagnostic is classified as:

  • MISRA-C-2012-20.6
  • MISRA-C-2023-20.6