|
1 | 1 | --- |
2 | 2 | title: "Visualize C/C++ macro expansion" |
3 | 3 | description: "Learn how to use Visual Studio to visualize C/C++ macro expansion." |
4 | | -ms.date: 02/02/2024 |
| 4 | +ms.date: 03/07/2024 |
5 | 5 | ms.topic: "how-to" |
6 | 6 | f1_keywords: ["macro expansion", "macro visualization"] |
7 | 7 | helpviewer_keywords: ["macro expansion", "macro visualization"] |
@@ -44,31 +44,31 @@ Long macros can be difficult to read. Visual Studio can now expand C and C++ mac |
44 | 44 |
|
45 | 45 | You can inspect a macro's expanded value, even when several preprocessor steps are involved, by using the following steps: |
46 | 46 |
|
47 | | -1. Place the cursor on the `POWER` a macro in the sample. |
| 47 | +1. Place the cursor on the `POWER` macro inside `main()` in the sample. |
48 | 48 | 1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**: |
49 | 49 |
|
50 | 50 | :::image type="complex" source="media/visual-studio-2022-hover-macro.png" alt-text="Screenshot of the macro window, showing the POWER macro expansion."::: |
51 | 51 | 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. |
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`). The expansion of the macro, as a comment near your macro, looks like: ```// (((10.0 * 20.0)* (5.0 * 2.0)) / 2.0)```. |
| 55 | +1. Create a comment following the `POWER` line and choose paste (`Ctrl+V`). The expansion of the macro, as a comment near your macro, looks like: `// (((10.0 * 20.0)* (5.0 * 2.0)) / 2.0).` The keyboard shortcut for this action is `Ctrl+M` followed by `Ctrl+C`. |
56 | 56 |
|
57 | 57 | ## Expand a macro inline |
58 | 58 |
|
59 | 59 | Use the following steps to expand a macro inline, which replaces the macro with its expansion: |
60 | 60 |
|
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 | | -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;``` |
| 63 | +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`. |
64 | 64 |
|
65 | 65 | ## Visualize macro expansion |
66 | 66 |
|
67 | 67 | 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: |
68 | 68 |
|
69 | 69 | 1. Place the cursor on the `WORK` macro in the previous example. |
70 | 70 | 1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**. |
71 | | -1. Choose **Visualize Expansion**. |
| 71 | +1. Choose **Visualize Expansion**. The keyboard shortcut for this action is `Ctrl+M` followed by `Ctrl+V`. |
72 | 72 | 1. The macro expansion window appears. The first expansion of the `WORK` macro is visible: `(FORCE() * DISTANCE())`: |
73 | 73 |
|
74 | 74 | :::image type="complex" source="media/visual-studio-2022-work-macro-expansion.png" alt-text="Screenshot of the macro expansion window, which allows you to step through the WORK macro expansion one step at a time."::: |
|
0 commit comments