5

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

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Frames Catherine White
  • 25,873
  • 19
  • 84
  • 134

5 Answers5

8

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

dbush
  • 186,650
  • 20
  • 189
  • 240
jitter
  • 52,771
  • 11
  • 107
  • 123
  • For MSVS users, see this old question: http://stackoverflow.com/questions/1719234/see-what-the-preprocessor-is-doing – DarenW Jan 16 '10 at 21:02
7

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

gcc -E source.c
caf
  • 225,337
  • 36
  • 308
  • 455
7

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
  • 103,426
  • 11
  • 122
  • 196
2

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

Stephan202
  • 57,780
  • 13
  • 124
  • 131
1

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

  • Obtaining final macro expansion
  • Looking through expansion process step-by-step

This is called Macro Exploration control.

DrYap
  • 6,345
  • 2
  • 29
  • 54
Konstantin Tenzin
  • 11,764
  • 3
  • 21
  • 20