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

前端 未结 10 949
一个人的身影
一个人的身影 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:17

    Most compilers have an option to just run the preprocessor. e.g., gcc provides -E:

       -E  Stop after the preprocessing stage; do not run the compiler proper.  
           The output is in the form of preprocessed source code, which is sent
           to the standard output.
    

    So you can just run:

    gcc -E foo.c
    

    If you can't find such an option, you can also just find the C preprocessor on your machine. It's usually called cpp and is probably already in your path. Invoke it like this:

    cpp foo.c
    

    If there are headers you need to include from other directories , you can pass -I/path/to/include/dir to either of these, just as you would with a regular compile.

    For Windows, I'll leave it to other posters to provide answers as I'm no expert there.

提交回复
热议问题