How to figure out what value MSVC is using for a preprocessor macro

倾然丶 夕夏残阳落幕 提交于 2019-12-11 02:11:16

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1342158/how-to-figure-out-what-value-msvc-is-using-for-a-preprocessor-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!