July 13th, 2023

Visualize Macro Expansion for C++

Mryam Girmay
Program Manager

We are excited to announce the availability of Visualize Macro Expansion in Visual Studio 17.7 Preview. This feature lets you visualize the step-by-step expansion of macros. To begin utilizing this feature, ensure that you update to the latest version of Visual Studio Preview.

Visualize Macro Expansion

Visual Studio has introduced an enhanced Macro Expansion feature. This feature brings significant benefits, enabling you to comprehend and review complex multi-level macro expansions in a step-by-step manner. When you hover over a macro, you can access Quick Info, which now includes the Visualize Expansion link in addition to the Copy and Expand Inline options. The Visual Expansion will enable you to visualize the preprocessor passes of the expansion.

Image of Visualize Expansion.
Image of Visualize Expansion.

The Visual Expansion link opens a new window that initially displays the first step of macro expansion. By utilizing the arrows next to the expansion step numbers, you can easily navigate through the subsequent steps of the expansion. This feature proves especially valuable in scenarios involving nested macros with lengthy expansions. In cases where nested macros have long expansions, this feature will help to precisely identify the actions taking place at each step, facilitating a deeper understanding of the macro’s behavior. Ultimately, this feature greatly enhances the efficiency of your debugging efforts, enabling you to pinpoint and resolve issues more effectively.  

 Gif for visualizing macro expansion process. 
Gif for visualizing macro expansion process.

Send us your feedback!

Download the latest version of Visual Studio Preview, and try out Visualize Macro ExpansionWe would love to hear your thoughts, so please share your feedback in the comments below, on Developer Community, or reach out to us on Twitter (@VisualC) or via email at visualcpp@microsoft.com. Your input is highly appreciated! 

 

 

 

 

 

Author

Mryam Girmay
Program Manager

8 comments

Discussion is closed. Login to edit/delete existing comments.

  • Lauri Vasama

    The font should probably be changed to use a monospace one by default. Perhaps the same font as the code editor.

  • Georgi Hadzhigeorgiev

    That’s a very nice feature, Mryam!

  • David Lowndes

    If I hover over a Windows SUCCEEDED macro, invoke the visualization for it, then click the right pointing blue arrow, it kills VS:
    Application: devenv.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.ArgumentOutOfRangeException
    at System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument, System.ExceptionResource)
    at System.Collections.Generic.List`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_Item(Int32)
    at Microsoft.VisualStudio.VC.MacroExpansionView.Forwards_Click(System.Object, System.Windows.RoutedEventArgs)
    at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
    at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)Read more