简体   繁体   中英

Preprocessor output

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 to my code.

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.

You can also call the C Preprocessor directly.

cpp infile outfile

Check out man cpp for more info.

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.

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.

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.

If using CLion by Jetbrains, you can use the action "clangd: Preprocess current TU"

So hit shift shift and start typing clangd...

动作弹出

Best assign it to a shortcut for simpler reuse in preferences->keymap:

在此处输入图片说明

Shout out to marcosbento

PS: TU means 'translation unit' (see here LLVM translation unit )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM