Expanding macros in a cpp/c file to another file!

Isn’t it nice to see how our macros get’s expanded into real code, well for this purpose VC++ compiler provides the following compiler switches…

  • /E – Preprocess to stdout
  • /EP – Preprocess to stdout  but no #line this time
  • /P – Preprocess to file*

* This is our man! add this switch to compilation settings of a project’s settings to see *.i files generated for every compiled file in a project.

Just take a look at the size of the file(.i file), it could well be in MB’s, the reason being that all include files also get’s included in the .i file since “#include” is also a preprocessor command.

Take a look at how ASSERT’s, VERIFY’s, BEGIN_MESSAGE_MAP’s get’s expanded.

Have fun learning and digging!

Appreciate your comments...