如何使用Visual Studio扩展VC ++宏引用?

时间:2013-11-10 19:34:58

标签: visual-studio visual-c++ macros preprocessor

是否可以扩展宏引用并查看传递给编译器的代码是什么样的,而不是右键单击宏标识符然后单击“转到定义”?

3 个答案:

答案 0 :(得分:15)

"项目+属性,C / C ++,预处理器,文件预处理=是。编译并打开构建目录中的.i文件。

答案 1 :(得分:4)

I heard all possible negative answers on the topic:

  • macros can only be expanded not evaluated
  • preprocessor should parse also include files
  • nested macros can be over-complicated
  • conditional preprocessing can be tricky
  • macros are evil just avoid them etc
  • etc....

They are all true, but IMO they collide with the reality of everydays programming.

In fact, working on old C project where macros, where mostly simply used as functions, this became of crucial importance for me. Generating all preprocessed files with /P works but is overkilling and time taking. I just needed a tool that expands a simple macro defined a few lines above or at maximum in other file.

How to do that?

  1. On Linux simply use GDB and his expand macros capabilities
  2. On windows I use https://www.jetbrains.com/resharper-cpp/ integrated into Visual Studio

So, Yes, in a practical sense, it is possible.

答案 2 :(得分:0)

自VS2017以来,您可以在快速信息工具提示中看到宏扩展。一个非常酷的新功能。

Macro Expansions in Quick Info Tooltips