views:

149

answers:

5

Is there anyway to see what you code looks like after the preprocessor has done all the substitutions?

+6  A: 

That depends on your compiler. With gcc, you would use:

gcc -E source.c
caf
thanks you, for the fast and accurate responce, i should havce mention i was ussing gcc.
Oxinabox
+5  A: 

For gcc jus use the -E switch

gcc -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.

jitter
For MSVS users, see this old question: http://stackoverflow.com/questions/1719234/see-what-the-preprocessor-is-doing
DarenW
+2  A: 

As an alternative to gcc -E, you can run cpp on your file.

Stephan202
+5  A: 

Just a note about system headers (eg <stdio.h>): they are a pain when preprocessed.

gcc -E -nostdinc file.c or cpp -nostdinc file.c will not include expansion of system headers.

pmg
A: 

Eclipse C++ IDE (CDT) has macro exploration control, which can be used for:

  • obtaining final macro expansion
  • looking threw expansion process step-by-step

This is called Macro Exploration control.

Konstantin