Macro Expansions in Quick Info Tooltips

With Visual Studio, we’re always looking for ways to save developers time and make them more productive. A good way to do this is to look at C/C++ language features that are difficult to work with, and make it easier to understand them. Today, we’re looking at macros. Macros are always a pain to deal with, yet they are one of those things that never seem to go away in C++. To make it easier to understand what a particular macro is doing, we are introducing a new feature: macro expansions in Quick Info tooltips. If you are already using Visual Studio, you may already know that you can hover over a code symbol (such as a variable) to quickly see the definition of that symbol, as well as any comments describing it (as long as those comments are present above the definition). As of Visual Studio 2017 version 15.8, when you hover over a macro, you get an additional line of information: the actual expansion of the macro that the preprocessor will replace during the first stage of compilation. Here is an example:

Macro Expansion in Quick Info

Hovering over a macro now shows the expansion of that macro.

For a very simple macro, like a macro defining a constant number such as Pi, this might not seem very useful, since the macro definition alone will tell you all you need to know. But when you have a macro that references other macros, getting the full expansion easily can save you a lot of time.

This feature is available today in the first 15.8 preview. You can download the latest preview build of Visual Studio that can run side by side with your release build from the Visual Studio website. Since this feature is still in preview, there are a few limitations which we plan to address in a future update. The following are a few cases where you will not yet see macro expansions:

  1. On #define statements
  2. On the condition blocks of #if / #ifdef statements
  3. When hovering on a macro that is used as an argument to a function-like macro (you can still hover on the function-like macro name itself instead though).

As always, we encourage you to try out the newest features via the Visual Studio 2017 Preview channel. 15.8 Preview 1 is available today, and you will find even more new features in future previews. If you run into any bugs, we would appreciate if you can file a bug report via Help > Send Feedback > Report A Problem from the IDE. If you have some ideas for new features that we should add to Visual Studio, you can post suggestions on UserVoice.