views:

374

answers:

3

I'm attempting to use a /D compiler option on MSVC6 to define a string, but there's something weird about using double quotes around it. To debug this problem, it would be extremely helpful for me to be able to see what value the preprocessor is actually substituting into my code where the macro is expanded. Is there any way I can do this? I tried creating a Listing file with "assembly and source", but the source contains the original macro name and the ASM is some incomprehensible gibberish at that line. Is there a way to get the macro value at compile time?

Failing that (or perhaps more useful), how do I specify a string with the /D option? It needs to substitute into my source with double quotes around it, since I'm using it as a string literal.

+2  A: 

Try one of the following options to CL.exe:

/E preprocess to stdout
/P preprocess to file

If you're building within Visual Studio, you can specify custom command-line options in one of the project property dialogs.

Brannon
/P did the job. I wonder why that was so hard to google for... Also, for anyone who is interested in the future, it appears (from trial and error) that you can escape the quotes in the /D string with a backslash.
rmeador
+1  A: 

MSVC has a compiler flag that allows you to see the preprocessed source file with all the macros expanded, comments removed, etc. - the entire translation unit in terms of the actual code that will compile. Preprocessed output should give you the insight you're looking for regarding your macro expansion. More info here.

fbrereto
+1  A: 

There's an option to pass to the compiler (/P) and it will write the preprocessor output into my_cpp_file.i where you can look at it.

sbi