How do I see a C/C++ source file after preprocessing in Visual Studio?

前端 未结 10 954
一个人的身影
一个人的身影 2020-11-22 05:44

Let\'s say I have a source file with many preprocessor directives. Is it possible to see how it looks after the preprocessor is done with it?

10条回答
  •  时光说笑
    2020-11-22 06:36

    You typically need to do some postprocessing on the output of the preprocessor, otherwise all the macros just expand to one liners, which is hard to read and debug. For C code, something like the following would suffice:

    gcc -E code.c | sed '/^\#/d' | indent -st -i2 > code-x.c
    

    For C++ code, it's actually a lot harder. For GCC/g++, I found this Perl script useful.

提交回复
热议问题