Preprocessed Source Code (MSVC)|
While browsing deep into the bowels of the MSDN library, I found a blurb
about outputing Preprocessed source code. I somehow managed to miss
these switches in the compiler reference..oops! Apparently, the compiler
switches /E, /P, and /EP allow you to view source code that has been
For the uninformed, viewing your preprocessed code can help
make sure that all macros are expanded properly and that the correct
directives are used (#ifdef...#endif). Of couse, browsing through
thousands and thousands of a game engine's processed code just to
inspect macro expansions and directives might be a little overkill...but
if you know that a certain piece of code is failing, checking macro
expansions can help catch some sneaky bugs.
Here's a simple example of a poorly written macro:
#define BAD_CUBE(x) x*x*x
// Correct version: #define GOOD_CUBE(x) ((x)*(x)*(x))
int i = 5;
int i_cubed = BAD_CUBE(i+2));
// BAD_CUBE expands to: i+2*i+2*i+2
// In BAD_CUBE, (*) has higher precedence than (+), so the code
// ends up like this: i + (2*i) + (2*i) +2
// GOOD_CUBE expands to: ((i+2)*(i+2)*(i+2))
Here are the combinations:
Option Output with #lines? Output
/E Yes stdout
/P Yes *.i file
/EP No stdout
/E /EP No stdout
/P /EP No *.i file
To preserve comments during preprocessing, add the /C switch.
Example: CL /P /C myfile.cpp // outputs to "myfile.i"
I don't know if any other compilers support a similar compiler switch.
But if you know of one that does, let me know! :)
I'm sure all of you programming gurus already knew about this switch,
but newbies like myself can use all the help we can get.<grin>
The zip file viewer built into the Developer Toolbox made use
of the zlib library, as well as the zlibdll source additions.