Skip to content

Commit 4fd05e8

Browse files
Taojunshen3836425+corob-msft@users.noreply.i.8713187.xyzPRMerger10hmacgregor1ttorble
authored
1/12/2021 AM Publish (#4041)
* Fix to `/fpcvt` per John Morgan email * Reformat WeakRef class document. * Update Advanced prop page and C1107 * Remove unrelated change. * Minimizing entity form of & (#3916) * Initial pass minimizing on &gt; entities (#3919) * Initial pass on &gt; entities * Fix everything. * Try without `&lt;` entities in title/desc * Clean up pass * Update docs/atl-mfc-shared/reference/cfiletime-class.md Co-authored-by: Tracey Torble <[email protected]> * Update tn026-ddx-and-ddv-routines.md `DoDialogExchange` -> `DoDataExchange` * Fix incorrect import example * github fix 3544 * GITHUB FIX FOR #3549 * Add UWP to list of unsupported ASAN features. * Fix misnamed mt.exe options. Acrolinx all. * Attempt fpcvt simplification per John Morgan. * Fix cpp-docs 3546 * Address complaint in cpp-docs 3554 (#3950) * Add section on CMake partial activation * 17.1 Update warnings, fix cpp-docs 3563 (#3954) * 17.1 Update warnings, fix cpp-docs 3563 * fix date * Add `/Zc:externC` compiler option doc, fix 1594 * Tweaks. * Fix links, header syntax issues * Fix issues in XML Docs reference * Make list match apparently intended style * Fix broken link. * Add docs for new check Signed-off-by: Kyle Reed <[email protected]> * fix toc * remove .md from toc title * Revert "Add docs for new linter check" * update runtime spelling * Bulk fix: remove HTML entities from yml headers (#3962) * Style and content fixes in cpp language docs * Changing confusing wording about C++ exceptions * Bulk fix HTML entities in H1 (#3966) * Fix lt-gt entity pairs * Bulk fix of `&lt;`-`&gt;` pairs in H1 headings * Oops, deleted initial `#` * Fix two more H1 issues * update with existing .openpublishing.publish.config.json * C++ tutorial landing page, attempt 2 * Revert redirection of get-started index.yml file * Fix typo * Bulk fix `&lt;`, `&gt;`, and `.period;` entities * operatoroperator * `/hotpatch`: No jump to the first instruction * Update Acrolinx for main branch * Change learn about item type * Add get started TOC * fix over machine translation problems (#3977) * fix over machine translation problems * acrolinx and misses * markdown fixes Co-authored-by: TylerMSFT <[email protected]> * Make the grammar bot happy * Fix things that look like parameters. (#3978) * Fix things that look like parameters. * Acrolinxy * Misc fixes * Other fixes * Fix typos * Acrolinx some more * [17.0] Update links to download Visual Studio (#3981) * Update links to download Visual Studio * Remove VS 2019 reference * Address cpp-docs 3565 * Also cpp-docs 439 * cpp-docs 947 * cpp-docs 1002 * accuratized * cpp-docs 1035 * Twhitney named modules (#3960) * draft * draft * draft * fix links * cleanup * added some more info * add some see also references * cleanup pass * remove text about overloads * tech review * little better wording * a little more word smithing * fix link * acrolinx * readthrough pass * Readthrough to test building the project * acrolinx * rename media file Co-authored-by: TylerMSFT <[email protected]> * cpp-docs 1305 * cpp-docs 1324 * address github issue #3524 and add code escape to prevent over machine translation * missed a couple escapes * couple more code escapes * one more escape * Address cpp-docs 3583: LNK1107 clarity * Tweaks * tweak formatting * Expand on fix for cpp-docs 1035 (#3986) * Expand of fix for cpp-docs 1035 * Mention overloads. * Grammar and formatting fixes * add summary of what will learn in module * [17.1p2] Add docs for comparison/bitwise c++ linter check. (#3964) * Revert "Revert "Add docs for new linter check"" This reverts commit e56971f. * PR feedback Signed-off-by: Kyle Reed <[email protected]> * Update cmake-presets-vs.md * Update cmake-presets-vs.md * Switch http to https and fix broken links * Acrolinx * Style pass for the grammar checker bot * Fix two incorrect conditions in the ARM packed exception handling For the prologue, the distinction between `mov r11, sp` and `add r11, sp, #xx` lies only in whether other registers are pushed before R11 and LR in prologue instruction 2. (The condition `R`==1 and `PF`==0 corresponds to no other registers pushed before `r11`.) The `L` flag doesn't affect it (and the documentation explicit says that when `C` is set, then `L` also must be set, thus `C`==1 and `L`==0 is tautological too). This was correctly described in the textual form, but the conditions in the table included one erronous case. For the epilogue, when `Ret`!=0, the function doesn't return by popping LR directly into PC, but with an explicit branch instruction (10a or 10b). In this case, if `L`==1, the LR register is included in the list of registers popped in instruction 8. If register homing is used (`H`==1), then instruction 9a is used instead of 9b. This case seemed to have been overlooked both in the textual description and in the table. Also, when prologue instruction form 3a is used, clarify that it corresponds to the unwind code FB (narrow nop) only, that unwinding such a prologue doesn't restore `sp` from `r11`. Also fix a typo and clarify that encodings with C=1, L=0 are invalid. * Address cpp-docs 3588 error in link commands (#3996) * Address cpp-docs 3588 error in link commands * Update ms.date * Acrolinx fixes to frontrun cpp-docs 3541 * Post-3541 acrolinx pass * Update how-to-marshal-structures-using-cpp-interop.md Change "=" into "-" * Add _CountOneBits[64] to the ARM64 intrinsic doc * Update .acrolinx-config.edn update to reflect default branch name change * Mark first code block as C++ Syntax highlighting did not work for the `using identifier = type;` block due to missing language information. * Fixed grammatical error in allocator-class.md "Constructing a container with a custom allocator provide control over allocation and freeing of that container's elements." -> "Constructing a container with a custom allocator provides control over allocation and freeing of that container's elements." * Update d-using-the-schedule-clause.md * Correct a word in the remarks of /DIRECTIVES. The section is .drectve instead of .drective. * std::is_standard_layout<Derived> * Make meaning clearer This makes the meaning clearer to me. The ". Or," seems like to strong of a separator for closely related phrases. * Update value-types-modern-cpp.md Commas to make the meaning clearer * add missing usage of CopyChars * update json examples (#4017) * update json examples * acrolinx Co-authored-by: TylerMSFT <[email protected]> * fix github issue #3600 * formatting cleanup and acrolinx * Address cpp-docs issues 3601 3622 3626 * Update deprecating-types-and-members-c-cx.md * PR review edit / relative link syntax * add code escape to prevent overtranslation * fix missed code elements and acrolinx * more cleanup * github fixes for #3635 and #3636 (#4026) * github fixes for #3635 and #3636 * acrolinx and cleanup * nit Co-authored-by: TylerMSFT <[email protected]> * Update windows-store-apps-the-windows-runtime-and-the-c-run-time.md * Broken link fixed (#4025) * Implement intrinics broken link fixes (#4028) * Update deprecating-types-and-members-c-cx.md Add code formatting to links to prevent overlocalization and markdown processing issues. * Update windows-store-apps-the-windows-runtime-and-the-c-run-time.md * Follow-up cpp-docs 3637 for style and Acrolinx * [17.0] Add compiler option `/option:strict` (#4002) * edit pass (#4035) * edit pass * acrolinx * acrolinx * minor edits Co-authored-by: TylerMSFT <[email protected]> * Fix non-blocking issues identified in #4032 Co-authored-by: [email protected] <[email protected]> Co-authored-by: PRMerger10 <[email protected]> Co-authored-by: Haig MacGregor <[email protected]> Co-authored-by: Tracey Torble <[email protected]> Co-authored-by: opbld17 <[email protected]> Co-authored-by: Waiting <[email protected]> Co-authored-by: opbld15 <[email protected]> Co-authored-by: opbld16 <[email protected]> Co-authored-by: roxk <[email protected]> Co-authored-by: TylerMSFT <[email protected]> Co-authored-by: Tyler Whitney <[email protected]> Co-authored-by: Laura Brenner <[email protected]> Co-authored-by: branh <[email protected]> Co-authored-by: John Ellison <[email protected]> Co-authored-by: PRMerger8 <[email protected]> Co-authored-by: PRMerger17 <[email protected]> Co-authored-by: Sam Freed <[email protected]> Co-authored-by: Colin Cooper <[email protected]> Co-authored-by: Paula Miller <[email protected]> Co-authored-by: Kyle Reed <[email protected]> Co-authored-by: Hannes Harnisch <[email protected]> Co-authored-by: Anna Huff <[email protected]> Co-authored-by: Ying Hua <[email protected]> Co-authored-by: Alex Guteniev <[email protected]> Co-authored-by: Dennis Rea <[email protected]> Co-authored-by: PRMerger3 <[email protected]> Co-authored-by: PRMerger18 <[email protected]> Co-authored-by: PRMerger Service account 2 <[email protected]> Co-authored-by: Jonathan Sweemer <[email protected]> Co-authored-by: Martin Storsjö <[email protected]> Co-authored-by: Kristine Toliver <[email protected]> Co-authored-by: AndreaLu <[email protected]> Co-authored-by: Matt Gardner <[email protected]> Co-authored-by: Sarah Vilaysom <[email protected]> Co-authored-by: Matthias <[email protected]> Co-authored-by: James Oswald <[email protected]> Co-authored-by: Anton Curmanschii <[email protected]> Co-authored-by: ROOOO <[email protected]> Co-authored-by: luozhiya <[email protected]> Co-authored-by: Zane Hitchcox <[email protected]> Co-authored-by: Chris Ho <[email protected]> Co-authored-by: PRMerger5 <[email protected]> Co-authored-by: Jaiganesh Kumaran <[email protected]> Co-authored-by: Jak Koke <[email protected]> Co-authored-by: atikmapari <[email protected]> Co-authored-by: Linda Spiller <[email protected]>
1 parent a8297be commit 4fd05e8

File tree

4 files changed

+77
-85
lines changed

4 files changed

+77
-85
lines changed

docs/build/walkthrough-header-units.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about C++ header units by converting a header file to a header unit by using Visual Studio 2019."
33
title: "Walkthrough: Build and import header units in Visual C++ projects"
4-
ms.date: "5/18/2021"
4+
ms.date: 01/10/2022
55
ms.custom: "conceptual"
66
author: "tylermsft"
77
ms.author: "twhitney"
@@ -12,7 +12,7 @@ helpviewer_keywords: ["import", "header unit", "ifc"]
1212

1313
This article is about building and importing header units by using Visual Studio 2019. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md) to learn specifically how to import Standard Template Library headers as header units.
1414

15-
Header units are the recommended alternative to [precompiled header files](creating-precompiled-header-files.md) (PCH). They're easier to set up and use than [shared PCH](https://devblogs.microsoft.com/cppblog/shared-pch-usage-sample-in-visual-studio), but they provide similar performance benefits. Unlike a PCH, when a header unit changes, only it and its dependencies are rebuilt.
15+
Header units are the recommended alternative to [precompiled header files](creating-precompiled-header-files.md) (PCH). They're easier to set up and use than a [shared PCH](https://devblogs.microsoft.com/cppblog/shared-pch-usage-sample-in-visual-studio), but they provide similar performance benefits. Unlike a PCH, when a header unit changes, only it and what depends on it are rebuilt.
1616

1717
## Prerequisites
1818

@@ -26,27 +26,27 @@ An important difference between a header unit and a header file is that header u
2626

2727
A similarity is that everything visible from a header file is also visible from a header unit.
2828

29-
Before you can import a header unit, you need to compile a header file into a header unit. An advantage of header units over PCH is that they can be used in distributed builds. For example, as long as you're using the same compiler to compile the *`.ifc`* and the program that imports it and are targeting the same platform and architecture, a header unit produced on one computer can be used on another.
29+
Before you can import a header unit, you need to compile a header file into a header unit. An advantage of header units over PCH is that they can be used in distributed builds. For example, as long as you compile the *`.ifc`* and the program that imports it with the same compiler, and target the same platform and architecture, a header unit produced on one computer can be used on another.
3030

31-
Another advantage of header units over PCH is that there's more flexibility for the compiler flags used to compile the header unit and for the program that imports it. With a PCH, more compiler flags must be the same. But with header units, these flags should be the same:
31+
Another advantage of header units over PCH is that there's more flexibility for differences between the compiler flags used to compile the header unit and the program that imports it. With a PCH, more compiler flags must be the same. With header units, only the following flags need to be the same:
3232

3333
- Exception handling options like **`/EHsc`**.
3434
- **`/MD[d]`** or **`MT[d]`**.
35-
- **`/D`**. You can define additional macros when you build the program that imports the header unit. But the ones used to build the header unit should also be present and defined the same way when you build the program that imports the header unit.
35+
- **`/D`**. You can define other macros when you build the program that imports the header unit. But the ones used to build the header unit should also be present and defined the same way when you build the program that imports the header unit.
3636

3737
## Ways to compile a header unit
3838

3939
There are several ways to compile a file into a header unit:
4040

4141
- **Automatically scan for header units**. This approach is best suited to smaller projects that include many different header files. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach1) for a demonstration of this approach. This approach is better suited to smaller projects because it can't guarantee optimal build throughput. That's because it scans all the files to find what should be built into header units.
4242

43-
- **Build a shared header unit project**. This approach is best suited for larger projects and for when you want more control over the organization of the imported header units. You create a static library project (or projects) that contain the header units that you want. Then reference the library project (or projects) from the project that then imports the header units it needs. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach2) for a demonstration of this approach.
43+
- **Build a shared header unit project**. This approach is best suited for larger projects and for when you want more control over the organization of the imported header units. You create a static library project (or projects) that contain the header units that you want. Then reference that library project (or projects) to import the header units. See [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach2) for a demonstration of this approach.
4444

45-
- **Choose individual header units to build**. This approach gives you file-by-file control over which header files are treated as header units. It's also a good way to quickly and selectively try out header units in your project. This approach is demonstrated in this walkthrough.
45+
- **Choose individual header units to build**. This approach gives you file-by-file control over which header files are treated as header units. It's also a good way to try out header units in your project. This approach is demonstrated in this walkthrough.
4646

4747
## Convert a project to use header units
4848

49-
In this example, you'll compile a header file as a header unit. Start by creating the following project in Visual Studio:
49+
Compile a header file as a header unit using the following steps in Visual Studio:
5050

5151
1. Create a new C++ console app project.
5252
1. Replace the source file content as follows:
@@ -61,7 +61,7 @@ In this example, you'll compile a header file as a header unit. Start by creatin
6161
}
6262
```
6363

64-
1. Add a header file called `Pythagorean.h`, and replace its content with this code:
64+
1. Add a header file called `Pythagorean.h` and then replace its content with this code:
6565

6666
```cpp
6767
#ifndef PYTHAGOREAN
@@ -76,31 +76,29 @@ In this example, you'll compile a header file as a header unit. Start by creatin
7676
#endif
7777
```
7878

79-
To enable header units, first set the **C++ Language Standard** to [`/std:c++20`](./reference/std-specify-language-standard-version.md) or later.
79+
To enable header units, first set the **C++ Language Standard** to [`/std:c++20`](./reference/std-specify-language-standard-version.md) or later:
8080

8181
1. On the Visual Studio main menu, select **Project** > **Properties**.
8282
1. In the left pane of the project property pages window, select **Configuration Properties** > **General**.
83-
1. In the **C++ Language Standard** list, select **ISO C++20 Standard (/std:c++20)** or later. (In versions before Visual Studio 2019 version 16.11, select **Preview - Features from the Latest C++ Working Draft (/std:c++latest)**.)
83+
1. In the **C++ Language Standard** list, select **ISO C++20 Standard (/std:c++20)** or later. In versions before Visual Studio 2019 version 16.11, select **Preview - Features from the Latest C++ Working Draft (/std:c++latest)**.
8484

8585
### Compile a header file as a header unit
8686

87-
In **Solution Explorer**, select the file you want to compile as a header unit. Right-click the file and select **Properties**. Then do one of the following, depending on the file type:
88-
89-
**For header files**:
90-
91-
Set the **Item Type** property to **C/C++ compiler**. By default, header files have an **Item Type** of **C/C++ header**. Setting this property also sets **C/C++** > **Advanced** > **Compile As** to **Compile as C++ Header Unit (/exportHeader)**.
87+
In **Solution Explorer**, select the file you want to compile as a header unit (in this case, `Pythagorean.h`). Right-click the file and select **Properties**. Since this is a header file, set the **Item Type** property to **C/C++ compiler**. By default, header files have an **Item Type** of **C/C++ header**. Setting this property also sets **C/C++** > **Advanced** > **Compile As** to **Compile as C++ Header Unit (/exportHeader)**.
9288
:::image type="content" source="media/change-item-type.png" alt-text="Screenshot that shows changing the item type to C/C++ compiler.":::
9389

94-
**For source files** (or header files that don't have an *`.h`* or *`.hpp`* extension):
90+
**Compile a source file as a header unit**:
9591

96-
Set the **Compile As** property to **Compile as C++ Header Unit (/exportHeader)**.
92+
If you want to compile a file that doesn't have an *`.h`* or *`.hpp`* extension as a header unit, set the **Compile As** property to **Compile as C++ Header Unit (/exportHeader)**.
9793
:::image type="content" source="media/change-compile-as.png" alt-text="Screenshot that shows changing Compile As to Compile as C++ Header Unit.":::
9894

9995
### Change your code to import a header unit
10096

101-
In the source file for the example project, that is, the file that contains `main()`, change `#include "Pythagorean.h"` to `import "Pythagorean.h";`. (Don't forget the trailing semicolon that's required for `import` statements.) When you're compiling a header unit from a system header, use angle brackets (`import <file>;`). If it's a project header, use `import "file";`.
97+
In the source file for the example project that contains `main()`, change `#include "Pythagorean.h"` to `import "Pythagorean.h";`. Don't forget the trailing semicolon that's required for `import` statements.
98+
99+
When compiling a header unit from a system header, use angle brackets (`import <file>;`). If it's a project header, use `import "file";`.
102100

103-
Build the solution. (**Build** > **Build Solution** on the main menu.) Run it to see that it produces the expected output: `Pythagorean triple a:2 b:3 c:13`
101+
Build the solution by selecting **Build** > **Build Solution** on the main menu. Run it to see that it produces the expected output: `Pythagorean triple a:2 b:3 c:13`
104102

105103
In your own projects, repeat this process to compile the header files you want to import as header units.
106104

0 commit comments

Comments
 (0)