How to determine what value MSVC uses for a preprocessor macro

I'm trying to use the / MS compiler option to compile MSVC6 to define a string, but there is something weird about using double quotes around it. To debug this issue, it would be extremely helpful so that I can see what value the preprocessor is actually replacing my code with where the macro expands. Is there a way to do this? I tried to create a "build and source" listing file, but the source contains the original name of the macro, and ASM is weird gibberish on that line. Is there a way to get the value of a macro at compile time?

If this is not the case (or perhaps more useful), how do I specify a string with the / D option? It should replace my source with double quotes around it since I am using it as a string literal.

+2


source to share


3 answers


Try using CL.exe with one of the following options:

/E preprocess to stdout
/P preprocess to file

      



If you are building inside Visual Studio, you can specify custom command line parameters in one of the project properties dialogs.

+3


source


MSVC has a compiler flag that allows you to see the preprocessed source file with all macros, comments removed, etc. - the whole translation unit in terms of the actual code that will be compiled. The preprocessed output should give you the insight you're looking for regarding expanding your macro. More details here .



+1


source


There is an option to pass ( /P

) to the compiler and it will write the preprocessor output to my_cpp_file.i

where you can watch it.

+1


source







All Articles