0

Possible Duplicate:
Preprocessor output

I have found myself debugging STL Port for Android. It uses many (10-100?) preprocessor directives throughout to decide what code is actually output by the preprocessor. Lots of #if and #ifdef blocks.

Is there a tool available that can run through these and show what text is actually sent to the compiler? Is it possible to see the output of the preprocessor?

Community
  • 1
  • 1
Adam S
  • 8,945
  • 17
  • 67
  • 103

3 Answers3

2

In GCC, use gcc -E source.c to show the output of the preprocessor only.

Same for Clang I believe.

For other compilers, see the manual. This should be clearly documented.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • Wow, I can't believe I missed this! Thanks. One quick question: when reading the output, is it true that only the lines not starting with '#' are send to the compiler? – Adam S Jan 10 '12 at 22:29
  • @AdamS: Not really. The remaining directives are still needed by the compiler to produce the correct file name and line number output in error messages. – Kerrek SB Jan 10 '12 at 22:31
1

This is exactly what Boost.Wave was created for.

The Wave C++ preprocessor library is a Standards conformant implementation of the mandated C99/C++ preprocessor functionality packed behind a simple to use interface, which integrates well with the well known idioms of the Standard Template Library (STL).

ildjarn
  • 62,044
  • 9
  • 127
  • 211
0

Almost any C++ compiler I used has its command line switch to perform this task; on g++ it's -E (which writes the output on stdout, see the manpage), on VC++ it's /EP (output to stdout) or /P (output to file).

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299