How to print macros in msvc preprocessor?
c++, c-preprocessor, gcc, visual-c++
Solution
There is an undocumented compiler switch, `/d1PP`, that will retain macro definitions in the preprocessor output. If you compile Rado's example with `/P /d1PP`, you'll get the following output file:
#line 1 "q.cpp"
#define BLAH 1
int main()
{
cout << "BLAH defined" << endl;
#line 10 "q.cpp"
}
Note that this switch is not documented. It is thus not officially supported. It may be removed at any time, or its behavior may be changed at any time. It may have bugs. Use at your own risk, etc., etc.
Problem
Is there a way to see my #defines in preprocessor file using msvc or gcc? here's a little code: ``` #include <iostream> #define asdasdadda asdsad int main() { #ifdef asdasdadda std::cout << "yes\n"; #else std::cout << "no\n"; #endif return 0; } ``` I compile it with cl by this way: ``` $ cl main.cpp /C /P ``` And here's the tail of preprocessored main.i: ``` #line 2 "main.cpp" int main() { std::cout << "yes\n"; #line 13 "main.cpp" return 0; } ``` And here's that I expect: ``` #line 2 "main.cpp" #define asdasdadda asdsad int main() { std::cout << "yes\n"; #line 13 "main.cpp" return 0; } ``` gcc behaviour is the same...