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

This diagnostic rule is based on the [MISRA](https://misra.org.uk/) \(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:

```cpp
#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](https://godbolt.org/z/PT4nh645b) or [Clang](https://godbolt.org/z/c6zPoaovK) without defining the `FLAG` macro, the result will be one of the expected options:

```cpp
My program prints: hello.
```

However, a program compiled using [MSVC](https://godbolt.org/z/8x3K9fq81) will print an unexpected result:

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

The fixed code:

```cpp
#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](https://godbolt.org/z/4KEcr4xvd) depending on the `FLAG` macro definition\.