You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Long macros can be difficult to read. Visual Studio can now expand C and C++ macros, one step at a time, to make them easier to understand. You can copy the expanded macro if you want. This article allows you to experiment with these features.
11
+
Long macros can be difficult to read. Visual Studio can now expand C and C++ macros: you can get a copy on the clipboard of what the expanded macro will look like, replace the macro inline with its expansion, and step-by-step expand a macro so you can see what it looks like at each stage of expansion. This article allows you to experiment with these features.
12
12
13
13
## Prerequisites
14
14
@@ -19,30 +19,30 @@ Long macros can be difficult to read. Visual Studio can now expand C and C++ mac
19
19
1. Start Visual Studio 2022, version 17.5 or later, and create a C++ Console app.
You can easily inspect a macro's expanded value, even when several preprocessor steps are involved, by using the following steps:
45
+
You can inspect a macro's expanded value, even when several preprocessor steps are involved, by using the following steps:
46
46
47
47
1. Place the cursor on the `POWER` a macro in the sample.
48
48
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**:
@@ -52,7 +52,7 @@ You can easily inspect a macro's expanded value, even when several preprocessor
52
52
:::image-end:::
53
53
54
54
1. Choose **Copy**.
55
-
1. Create a comment following the `POWER` line and choose paste (`Ctrl+V`). You'll see the expansion of the macro as a comment near your macro: ```// (((10.0 * 20.0)* (5.0 * 2.0)) / 2.0)```. The keyboard shortcut for this action is `Ctrl+M` followed by `Ctrl+C`.
55
+
1. Create a comment following the `POWER` line and choose paste (`Ctrl+V`). You'll see the expansion of the macro as a comment near your macro: ```// (((10.0 * 20.0)* (5.0 * 2.0)) / 2.0)```.
56
56
57
57
## Expand a macro
58
58
@@ -61,25 +61,25 @@ Use the following steps to expand a macro inline, which replaces the macro with
61
61
1. Place the cursor on the `POWER` macro in the previous example.
62
62
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**:
63
63
64
-
:::image type="complex" source="media/vs2022-hover-macro.png" alt-text="The macro window, showing the POWER macro expansion.":::
65
-
The macro window is open on POWER to show that it expands to (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0). Options to copy, expand inline, visual expansion, and search online appear at the bottom of the window.
66
-
:::image-end:::
64
+
:::image type="complex" source="media/vs2022-hover-macro.png" alt-text="The macro window, showing the POWER macro expansion.":::
65
+
The macro window is open on POWER to show that it expands to (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0). Options to copy, expand inline, visual expansion, and search online appear at the bottom of the window.
66
+
:::image-end:::
67
67
68
-
1. Choose **Expand Inline**. The `POWER()` macro is replaced with its expanded value: ```std::cout << "Power: " << (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0) << std::endl;```. The keyboard shortcut for this action is `Ctrl+M` followed by `Ctrl+I`.
68
+
1. Choose **Expand Inline**. The `POWER()` macro is replaced with its expanded value: ```std::cout << "Power: " << (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0) << std::endl;```.
69
69
70
70
## Visualize macro expansion
71
71
72
72
You can expand a macro one step at a time. This is useful when there are nested macros and you want to see the expansion step-by-step. To visualize the macro expansion for the `WORK` macro, use the following steps:
73
73
74
74
1. Place the cursor on the `WORK` macro in the previous example.
75
-
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**:
75
+
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**.
76
+
1. Choose **Visualize Expansion**.
77
+
1. The macro expansion window appears. The first expansion of the `WORK` macro is visible: `(FORCE() * DISTANCE())`:
76
78
77
-
:::image type="complex" source="media/vs2022-work-macro.expansion.png" alt-text="The macro expansion window, which allows you to step through the WORK macro expansion one step at a time.":::
78
-
The macro visualization window is open on FORCE to show that it initially expands to (FORCE()*DISTANCE()). There are single angle brackets in the window for moving forwards and backwards a single expansion at a time. The double angle brackets fully expand or fully undo the macro expansion.
79
-
:::image-end:::
79
+
:::image type="complex" source="media/vs2022-work-macro.expansion.png" alt-text="The macro expansion window, which allows you to step through the WORK macro expansion one step at a time.":::
80
+
The macro visualization window is open on FORCE to show that it initially expands to (FORCE()*DISTANCE()). There are single angle brackets in the window for moving forwards and backwards a single expansion at a time. The double angle brackets fully expand or fully undo the macro expansion.
81
+
:::image-end:::
80
82
81
-
1. Choose **Visualize Expansion**. The keyboard shortcut for this action is `Ctrl+M` followed by `Ctrl+V`.
82
-
1. The macro expansion window appears. The first expansion of the `WORK` macro is visible: `(FORCE() * DISTANCE())`.
83
83
1. Click the right angle bracket to expand the `FORCE` macro. The window now shows the `FORCE` macro expansion: `(MASS * ACCELERATION) * DISTANCE()`.
84
84
1. Click the right angle bracket to expand another step. The window now shows the `FORCE` macro expansion: `((10.0 * ACCELERATION) * DISTANCE())`.
0 commit comments