how to expand VC++ macro references using Visual Studio?

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


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

Macro Expansions in Quick Info Tooltips


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.