Rather than right clicking on the macro identifier and then on "go to definition", is it possible to expand macro references and see what the code that is passed to the compiler looks like?

有帮助吗?

解决方案

"Project + Properties, C/C++, Preprocessor, Preprocess to a File = Yes. Compile and open the .i file in the build directory.

其他提示

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.

You can see the macro expansion in the quick info tooltips since VS2017. A very cool new feature.

Macro Expansions in Quick Info Tooltips

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top