Preprocessor output

后端 未结 5 969
灰色年华
灰色年华 2020-11-27 04:39

How do I view the output produced by the C pre-processor, prior to its conversion into an object file?

I want to see what the MACRO definitions do t

相关标签:
5条回答
  • 2020-11-27 05:17

    You can check out my script described here:

    http://mosermichael.github.io/cstuff/all/projects/2011/09/16/preprocessor.html

    It formats the preprocessor output into a (hopefully) readable html document: lines that are different due to preprocessor are marked in the file.

    0 讨论(0)
  • 2020-11-27 05:22

    It depends on the compiler you use.
    With GCC, you can specify the -E flag on the command-line to let the compiler produce the pre-processor output.

    0 讨论(0)
  • 2020-11-27 05:27

    You can also call the C Preprocessor directly.

    cpp infile outfile
    

    Check out man cpp for more info.

    0 讨论(0)
  • 2020-11-27 05:30
    gcc -E file.c
    

    or

    g++ -E file.cpp
    

    will do this for you. The -E switch forces the compiler to stop after the preprocessing phase, spitting all it’s got at the moment to standard output.

    Note: Surely you must have some #include directives. The included files get preprocessed, too, so you might get lots of output.

    For Visual C++ the switch is /E which spits the preprocessor output to screen.

    0 讨论(0)
  • 2020-11-27 05:38

    For GCC,

    gcc -E -dM file.c
    

    or

    g++ -E -dM file.cpp
    

    should do the job. -dM, as GNU Preprocessor manual puts it, should generate a list of ‘#define’ directives for all the macros defined during the execution of the preprocessor, including predefined macros.

    0 讨论(0)
提交回复
热议问题