5

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137

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
  • 205,898
  • 23
  • 218
  • 273
jitter
  • 53,475
  • 11
  • 111
  • 124
  • 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
  • 233,326
  • 40
  • 323
  • 462
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
  • 106,608
  • 13
  • 126
  • 198
2

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

Stephan202
  • 59,965
  • 13
  • 127
  • 133
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,525
  • 2
  • 31
  • 54
Konstantin Tenzin
  • 12,398
  • 3
  • 22
  • 20