Skip to content

Commit 91546d1

Browse files
TylerMSFTTylerMSFT
authored andcommitted
fix indentation, remove keyboard shortcuts
1 parent d44638a commit 91546d1

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

docs/ide/visualize-macro-expansion.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Visualize C/C++ macro expansion"
33
description: "Learn how to use Visual Studio to visualize C/C++ macro expansion."
4-
ms.date: 02/01/2024
4+
ms.date: 02/02/2024
55
ms.topic: "how-to"
66
f1_keywords: ["macro expansion", "macro visualization"]
77
helpviewer_keywords: ["macro expansion", "macro visualization"]
88
---
99
# Visualize C/C++ macro expansion
1010

11-
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.
1212

1313
## Prerequisites
1414

@@ -19,30 +19,30 @@ Long macros can be difficult to read. Visual Studio can now expand C and C++ mac
1919
1. Start Visual Studio 2022, version 17.5 or later, and create a C++ Console app.
2020
1. Replace the default code with:
2121

22-
```cpp
23-
#include <iostream>
24-
25-
#define MASS 10.0
26-
#define ACCELERATION 20.0
27-
#define SPEED 5.0
28-
#define TIME 2.0
29-
#define DISTANCE() (SPEED * TIME)
30-
#define FORCE()(MASS * ACCELERATION)
31-
#define WORK()(FORCE() * DISTANCE())
32-
#define POWER()(WORK()/TIME)
33-
34-
int main()
35-
{
36-
std::cout << "Distance: " << DISTANCE() << std::endl;
37-
std::cout << "Force: " << FORCE() << std::endl;
38-
std::cout << "Work: " << WORK() << std::endl;
39-
std::cout << "Power: " << POWER() << std::endl;
40-
}
41-
```
42-
22+
```cpp
23+
#include <iostream>
24+
25+
#define MASS 10.0
26+
#define ACCELERATION 20.0
27+
#define SPEED 5.0
28+
#define TIME 2.0
29+
#define DISTANCE() (SPEED * TIME)
30+
#define FORCE()(MASS * ACCELERATION)
31+
#define WORK()(FORCE() * DISTANCE())
32+
#define POWER()(WORK()/TIME)
33+
34+
int main()
35+
{
36+
std::cout << "Distance: " << DISTANCE() << std::endl;
37+
std::cout << "Force: " << FORCE() << std::endl;
38+
std::cout << "Work: " << WORK() << std::endl;
39+
std::cout << "Power: " << POWER() << std::endl;
40+
}
41+
```
42+
4343
## Copy an expanded macro
4444

45-
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:
4646
4747
1. Place the cursor on the `POWER` a macro in the sample.
4848
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
5252
:::image-end:::
5353
5454
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)```.
5656

5757
## Expand a macro
5858

@@ -61,25 +61,25 @@ Use the following steps to expand a macro inline, which replaces the macro with
6161
1. Place the cursor on the `POWER` macro in the previous example.
6262
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**:
6363

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:::
6767

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;```.
6969

7070
## Visualize macro expansion
7171

7272
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:
7373

7474
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())`:
7678

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:::
8082

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())`.
8383
1. Click the right angle bracket to expand the `FORCE` macro. The window now shows the `FORCE` macro expansion: `(MASS * ACCELERATION) * DISTANCE()`.
8484
1. Click the right angle bracket to expand another step. The window now shows the `FORCE` macro expansion: `((10.0 * ACCELERATION) * DISTANCE())`.
8585

0 commit comments

Comments
 (0)