C ++ preprocessor does not handle the definition as expected

I'm having problems with the cpp preprocessor. I have this Input.h file as follows:

#ifndef PLATFORM_MOBILE1111
    #define MyTest WEB111
#endif 

int MyTest;

I process it with this command (on OSX):

cpp -E -P Source/Input.h Generated/Output.h

I get this:

    #define MyTest WEB111


int MyTest;

i.e. MyTest macro is not applied. Why?


After several experiments, I found that if I insert an empty line, variable definition, comment, or any other line after the #ifndef line, then this works fine.

#ifndef PLATFORM_MOBILE1111

    #define MyTest WEB111
#endif 

int MyTest;

Thus, the result entered above is processed correctly:

int WEB111;

Can someone explain to me why this is happening? and how to solve it? Is there an option I can go through?


Edit: I also found that ## (the concatenation operator) doesn't work either!

+6
2

, c++, cpp :

c++ -E -P Source/Input.h Generated/Output.h

: -x c++, c/++ c++. cpp .

+1

! clang!

(Apple LLVM version 8.1.0 (clang-802.0.42)) OSX.

, , #define (), , #defines #ifdefs.

, , , #define , - . , , #define .

( ):

 #define MyTest WEB111
int MyTest;

, :

#define MyTest WEB111
int MyTest;

WEB222:

 #define MyTest WEB111
 #define MyTest WEB222
int MyTest;

WEB111:

#define MyTest WEB111
 #define MyTest WEB222
int MyTest;

! 1!!: -)

, #define.

"": :

gcc -E Source/Input.cpp -P -o Generated/Output.cpp

, , LLVM.

, , gcc , cpp. cpp.

+3

All Articles