Five productivity features for C++ in Visual Studio 2017 15.8

A couple of weeks ago, version 15.8 of Visual Studio 2017 was finally released. You can read here about the new things available in this version. In this post, I will discuss five productivity features available for C++ development.

Macro expansion in Quick Info tooltips

In Visual Studio you can see the definition of a macro (including comments from above) when you hover the caret over a symbol. But in this version, you can see the actual expansion of the macro that the preprocessor is doing.

Obviously, this is useful for more complex macros, not simple values that you could already see from the preview of the definition. It doesn’t work in some situations: on #define statements, on the condition blocks of #ifdef statements, and when hovering on a macro that is used as an argument to a function-like macro.

What could be even more useful is having these expansions actually evaluated if possible. Like in the example above, there is an arithmetical expression that can be fully evaluated and have the result displayed too. But, perhaps, that’s too much to ask for.

See more: Macro Expansions in Quick Info Tooltips

Converting macros to constexpr

Macros are evil and you should try to avoid them as much as possible. Many macros can be actually replaced with a constexpr. Here are a couple examples:

In version 15.8, Visual Studio can help to convert macros to constexpr with a refactoring option.

Not all macros are convertible to constant expressions and sometimes this operation may fail or may not produce the best conversion, in which case you can modify the result manually.

See more: Convert Macros to Constexpr

Template IntelliSense

Template parameters can be annotated with information so that IntelliSense can be enabled in the template body. This annotation is user-specific, and therefore stored in the .vs folder and not shared on commits. Annotating the template parameters is done by clicking a new UI element (<T>) that appears next to a template definition when the caret is inside the template. With this extra info you get all the proper squiggles, quick info, parameter help, etc.

See more: Announcing Template IntelliSense

Just My Code stepping

In .NET it was possible to avoid going through non-user code when debugging with Step Into. This feature is now also available for C++. This means you can skip stepping into lots of library code such as STL code, or framworks such as MFC or ATL. You must have the Just My Code enabled from Tools > Options > Debugging > General > Enable Just My Code.

With this feature enabled, the debugger keeps track of which code is user code and which is not (code for which PDB information is available is considered user-code). When stepping into a function, execution will resume until another function that is marked as user code is reached or the current function completes its execution. Should you need to actually step into a non-user code function, then you can use the “Step Into Specific” command available in the editor’s context menu.

See more: Announcing C++ Just My Code Stepping in Visual Studio

Data breakpoints

Data breakpoints determine the debugger to stop the execution when a variable stored at a specific memory address changes its value. As a side note, you can only setup data breakpoints amounting to a total of 16 bytes. This could only be done from the Breakpoints window but is now available in the Locals, Autos, Watch, and Quickwatch windows, which will help to avoid switching between debugger windows. To do so, use the “Break When Value Changes” command from the window’s context menu.

See more: Data Breakpoints – Visual Studio 2017 15.8 Update

2 Comments on "Five productivity features for C++ in Visual Studio 2017 15.8"

  1. “It doesn’t work in some situations: on #define statements, on the condition blocks of #if/#ifdef statements, and when hovering on a macro that is used as an argument to a function-like macro.”

    Macro expansion actually does work on #if statements, just not #ifdef.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.