Skip to content

Commit 4f20ea7

Browse files
TaojunshenMugBergerFriesMichaelSquiresbradlitterellopbld17
authored
9/30/2022 AM Publish (#4553)
* Updated C6101 Mirror of my public PR. Added an example. Added proper spacing between headers and code blocks, matched formatting to my other PRs * Updated C6101 Minor changes in response to Acrolinx report * Updated C6101 More Acrolinx changes, split a run-on sentence * Updated C26495 Matched formatting to my other PRs. Added more information to the example. * Updated C26495 Fixed spelling error * Updated C6200 Matched formatting and wording to my other PRs. Added more information to the example * Updated C6200 Reworded to appease high-lord Acrolinx * Updated C6201 Matched formatting and wording to my other PRs. Matched the example to C6200 since they were functionally the same. * Updated C6200 Fixed output * Updated C6276 Matched formatting and wording with my other PRs. Added more information to the example * Updated C6276 Small to changes at the behest of Acrolinx * Updated C6277 Changed wording slightly, matched formatting and wording to my other PRs * Updated C6277 Changed wording, acquiesced to Acrolinx's request * Updated C6308 Changed wording to be more concise and less hostile. Changed the format and wording to match my other PRs * Updated C6308 Acrolinx changes * Updated C6200 Updated to the new format * Updated C6201 Updated to the new format * Updated C6201 Added code analysis name * Updated C6200 Added code analysis name * Updated C6276 Updated to the new format * Updated C6277 Updated to the new format * Update docs/code-quality/c6200.md Co-authored-by: Michael Squires <[email protected]> * Update docs/code-quality/c6200.md Co-authored-by: Michael Squires <[email protected]> * Updated C6200 Spacing fixed * Update docs/code-quality/c6201.md Co-authored-by: Michael Squires <[email protected]> * Updated C6201 Spacing fixed * Updated C6276 Removed third example and corrected earlier examples. Changed 3 space indentation to 4 to be consistent with my other PRs. Fixed spacing * Updated C6276 Consistent spacing * Updated C6101 Updated to the latest format * Updated C6101 Single backticks and InOut->Inout * Updated C6308 Updated to the new format, spacing made consistent with my other PRs * Updated C26495 Updated to the new format NOTE: This warning has no code analysis name. Per @MichaelSquires instructions, I omitted the usual keywords and 'Code analysis name:' section to match * Update compiler-warning-level-4-c4464.md @corob-msft proposal. I don't warrant it shouldn't be worded in a better way. * Update compiler-warning-level-4-c4464.md typo fix * Updated C6276 UNICODE/ANSI -> wide/narrow * Updated C6276 an -> a * Updated C6276 Updated to display new warning message * Updated C6276 char_t -> char * Updated C6201 Example now correctly shows a stack array * Updated C6200 Made example more obvious that the array was heap-allocated * Updated C6200 Added brackets to delete * Update docs/code-quality/c6308.md Co-authored-by: Michael Squires <[email protected]> * fix: delete unnecessary asterisk followup fix of MicrosoftDocs#4136 * optimize prime test * Update floating-point-support.md Explain what "ulp" stands for * Updated C6308 Changed example to initialize and declare variable sin the same line * Updates for cpp-docs 4161 * Update integritycheck-require-signature-check.md * alt-text * Update abstract-cpp-component-extensions.md * Add syntax highlighting to atl-mfc-shared * Updated C26495 Added code analysis ID * Updated C6201 Added stack-specific consequence to the description * alt-text updates * customer fix * minor updates * Incorporate changes in rewrite Updates for style and clarity. Also give it an Acrolinx pass. * Clarify version support * Tweak language for minimum support * Add code style, comment @MugBergerFries It's a good idea to use code styling for mentions of variable or class names (especially when they're easily confused generic names like "value"). I also added a comment to the fixed code sample to amplify the change and what it was doing. * acrolinx * cleanup pass * [BULK] DocuTune - Rebranding * alt-text updates * update alt-text * Fix Supported SSH algorithms * Update README.md * Address cpp-docs 4149 __umulh on ARM64 * Add slashes per cpp-docs 4150 * update alt-text code and removed 'experimental' from images * Update clang-support-msbuild.md Updated for better visibility of LLVMToolsVersion property. Note the text was also misleading because it kind of implies that LLVMToolsVersion supports side-by-side version of clang/LLVM in the same `LLVMInstallDir`, but that's not how clang/LLVM works. If you want to select a different version, you need to point it to a different path. * test fix * test fix * test fix * alt-text updates plus acrolinx * acrolinx * Split props file and IDE sections When both path and version are merged in the .props file discussion, a division between the .props approach and the IDE approach seems more natural than repeating the same content twice. * Update to add /std requirement * Test of build checks features * Update cpp-linter-overview.md * Provide F1 links to articles for VS linker properties (#4529) * Update F1 links for Linker Properties * F1 Project: Linker Properties part 1 * Finish Linker properties F1 links * Fix typo * Fix acrolinx related issues * Update dot-xmm.md Fixed overzealous replacement * [BULK UPDATE] DocuTune - Rebranding * Fix missing semicolon * Update files per cpp-docs 4181 * Add /ILK option per cpp-docs 4194 * Update per cpp-docs 4193 * Address cpp-docs 4186 code labels * template function -> function template * Acrolinx fixes. * Tweak language for 4178 update * Updates to main and wmain signatures * Acrolinx and style updates per review * Fix spelling, i18n, style, Acrolinx issues * Fix date. * Updated C6200 Removed extra asterisk in warning output * Updated C6201 Removed extra asterisks * Updated C6277 Removed extra asterisk * Updated C6308 Removed extra asterisk * Use correct warning message for C6201 Incorrectly copied warning message from C6200. * Quote actual warning message Quote the actual message, bad grammar and all, to make search happy. * Remove undefined quotes Simplify. Update date. Remove quotes from fully qualified, since we don't define it. * Give library functions code style Fix date. Also tweak a sentence for readability. * Update What's New for 17.3 (MicrosoftDocs#4552) * Update What's New for 17.3 * Fix link issue Co-authored-by: Samuel Berger <[email protected]> Co-authored-by: Michael Squires <[email protected]> Co-authored-by: Brad Litterell <[email protected]> Co-authored-by: opbld17 <[email protected]> Co-authored-by: Colin Robertson <[email protected]> Co-authored-by: opbld16 <[email protected]> Co-authored-by: Kisaragi <[email protected]> Co-authored-by: Courtney Wales <[email protected]> Co-authored-by: opbld15 <[email protected]> Co-authored-by: TylerMSFT <[email protected]> Co-authored-by: Bryan Gold <[email protected]> Co-authored-by: Edward Breeveld <[email protected]> Co-authored-by: Jeff Borsecnik <[email protected]> Co-authored-by: jsuther1974 <[email protected]> Co-authored-by: Austin Morton <[email protected]> Co-authored-by: Jak Koke <[email protected]> Co-authored-by: HO-COOH <[email protected]> Co-authored-by: prmerger-automator[bot] <40007230+prmerger-automator[bot]@users.noreply.github.com> Co-authored-by: James Barnett <[email protected]> Co-authored-by: Dennis Rea <[email protected]> Co-authored-by: Alex Buck <[email protected]> Co-authored-by: Tyler Whitney <[email protected]> Co-authored-by: ragingo <[email protected]> Co-authored-by: Feng Xu <[email protected]> Co-authored-by: Chuck Walbourn <[email protected]> Co-authored-by: Colin Cooper <[email protected]> Co-authored-by: Lychy <[email protected]> Co-authored-by: chausner <[email protected]> Co-authored-by: Stacyrch140 <[email protected]> Co-authored-by: Paula Miller <[email protected]> Co-authored-by: Stephanie Savell <[email protected]> Co-authored-by: Linda Spiller <[email protected]>
1 parent 4e0c557 commit 4f20ea7

5 files changed

+78
-43
lines changed

docs/build/walkthrough-header-units.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about C++ header units. Convert a header file to a header unit using Visual Studio 2022."
33
title: "Walkthrough: Build and import header units in Visual C++ projects"
4-
ms.date: 05/12/2022
4+
ms.date: 09/29/2022
55
ms.custom: "conceptual"
66
author: "tylermsft"
77
ms.author: "twhitney"
@@ -22,15 +22,15 @@ To use header units, you need Visual Studio 2019 16.10 or later.
2222

2323
A header unit is a binary representation of a header file. A header unit ends with an *`.ifc`* extension. The same format is used for named modules.
2424

25-
An important difference between a header unit and a header file is that a header unit isn't affected by macro definitions outside of the header unit. That is, you can't `#define` a symbol that causes the header unit to behave differently. By the time you import the header unit, the header unit is already compiled. This is different than how an `#include` file is treated because the included file can be affected by a macro definition outside of the header file. This is because the header file isn't compiled yet. It will go through the preprocessor when the source file that includes it is compiled.
25+
An important difference between a header unit and a header file is that a header unit isn't affected by macro definitions outside of the header unit. That is, you can't define a preprocessor symbol that causes the header unit to behave differently. By the time you import the header unit, the header unit is already compiled. It's different from how an `#include` file is treated, because an included file can be affected by a macro definition outside of the header file, because the header file isn't compiled yet. It goes through the preprocessor when you compile the source file that includes it.
2626

27-
Header units can be imported in any order. This isn't true of header files because macro definitions defined in one header file might affect a subsequent header file. Macro definitions in one header unit can't affect another header unit.
27+
Header units can be imported in any order, which isn't true of header files. Header file order matters because macro definitions defined in one header file might affect a subsequent header file. Macro definitions in one header unit can't affect another header unit.
2828

2929
Everything visible from a header file is also visible from a header unit, including macros defined within the header unit.
3030

31-
A header file must be translated into a header unit before it can be imported. 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 consumed on another. Unlike a PCH, when a header unit changes only it and what depends on it rebuild. Header units can be up to a magnitude smaller in size than a traditional `.pch`.
31+
A header file must be translated into a header unit before it can be imported. 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 consumed on another. Unlike a PCH, when a header unit changes, only it and what depends on it are rebuilt. Header units can be up to an order of magnitude smaller in size than a traditional `.pch`.
3232

33-
Header units impose fewer constraints on the parity of compiler switches used to create the header unit and to compile the code that consumes it than a PCH does. However, some switch combinations and macro definitions might create one definition rule (ODR) violations between various translation units.
33+
Header units impose fewer constraints on the parity of compiler switches used to create the header unit and to compile the code that consumes it than a PCH does. However, some switch combinations and macro definitions might create violations of the one definition rule (ODR) between various translation units.
3434

3535
Finally, header units are more flexible than a PCH. With a PCH, you can't choose to bring in only one of the headers in the PCH--the compiler processes all of them. With header units, even when you compile them together into a static library, you only bring the contents of the header unit you import into your application.
3636

@@ -44,11 +44,11 @@ There are several ways to compile a file into a header unit:
4444

4545
- **Choose individual files to translate into header units**. This approach gives you file-by-file control over what is treated as a header unit. It's also useful when you must compile a file as a header unit that, because it doesn't have the default extension (`.ixx`, `.cppm`, `.h`, `.hpp`), wouldn't normally be compiled into a header unit. This approach is demonstrated in this walkthrough. To get started, see [Approach 1: Choose individual header units to build](#approach1).
4646

47-
- **Build a shared header unit project**. This is the recommended approach and provides more control over the organization and reuse of the imported header units. Create a static library project that contains the header units that you want and then reference it to import the header units. For a walkthrough of this approach, see [Build a header unit static library project for header units](walkthrough-import-stl-header-units.md#approach2).
47+
- **Build a shared header unit project**. We recommend this approach because it provides more control over the organization and reuse of the imported header units. Create a static library project that contains the header units that you want and then reference it to import the header units. For a walkthrough of this approach, see [Build a header unit static library project for header units](walkthrough-import-stl-header-units.md#approach2).
4848

4949
- **Automatically scan for and build header units**. This approach is convenient, but is best suited to smaller projects because it doesn't guarantee optimal build throughput. For details about this approach, see [Approach 2: Automatically scan for header units](#approach2).
5050

51-
- As mentioned in the introduction, you can build and import STL header files as header units and automatically treat `#include` for STL library headers as `import` without rewriting your code. To see how, visit [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md).
51+
- As mentioned in the introduction, you can build and import STL header files as header units, and automatically treat `#include` for STL library headers as `import` without rewriting your code. To see how, visit [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md).
5252

5353
## <a name="approach1"></a>Approach 1: Choose header units to build
5454

@@ -97,31 +97,31 @@ Compile the header file as a header unit:
9797

9898
:::image type="content" source="media/change-item-type.png" alt-text="Screenshot that shows changing the item type to C/C++ compiler.":::
9999

100-
Later in this walkthrough, when you build this project, `Pythagorean.h` will be translated into a header unit. That's because the item type for this header file is set to **C/C++ compiler**, and because the default action for `.h` and `.hpp` files set this way is to translate the file into a header unit.
100+
When you build this project later in this walkthrough, `Pythagorean.h` will be translated into a header unit. It's translated because the item type for this header file is set to **C/C++ compiler**, and because the default action for `.h` and `.hpp` files set this way is to translate the file into a header unit.
101101

102102
> [!NOTE]
103103
> This isn't required for this walkthrough, but is provided for your information. To compile a file as a header unit that doesn't have a default header unit file extension, like `.cpp` for example, set **Configuration properties** > **C/C++** > **Advanced** > **Compile As** to **Compile as C++ Header Unit (/exportHeader)**:
104104
> :::image type="content" source="media/change-compile-as.png" alt-text="Screenshot that shows changing Configuration properties > C/C++ > Advanced > Compile As to Compile as C++ Header Unit (/exportHeader).":::
105105
106106
### Change your code to import a header unit
107107

108-
1. In the source file for the example project, change `#include "Pythagorean.h"` to `import "Pythagorean.h";` Don't forget the trailing semicolon that's required for `import` statements. Because it's a header file in a directory local to the project, we used quotes with the `import` statement, that is: `import "file";` In your own projects, to compile a header unit from a system header, use angle brackets: `import <file>;`
108+
1. In the source file for the example project, change `#include "Pythagorean.h"` to `import "Pythagorean.h";` Don't forget the trailing semicolon that's required for `import` statements. Because it's a header file in a directory local to the project, we used quotes with the `import` statement: `import "file";`. In your own projects, to compile a header unit from a system header, use angle brackets: `import <file>;`
109109

110110
1. 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`
111111

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

114-
If you want to convert only a few header files to header units, this approach is good. But if you have many header files that you want to compile, and the convenience of having the build system automatically handle it outweighs the potential impact on build performance, see the following section.
114+
If you want to convert only a few header files to header units, this approach is good. But if you have many header files that you want to compile, and the potential loss of build performance is outweighed by the convenience of having the build system handle them automatically, see the following section.
115115

116116
If you're interested in specifically importing STL library headers as header units, see [Walkthrough: Import STL libraries as header units](walkthrough-import-stl-header-units.md#approach1).
117117

118118
## <a name="approach2"></a>Approach 2: Automatically scan for and build header units
119119

120-
Due to scanning all of your source files to find and build header units, this approach is best suited for smaller projects because it doesn't guarantee optimal build throughput.
120+
Because it takes time to first scan all of your source files for header units, and then build them, this approach is best suited for smaller projects. It doesn't guarantee optimal build throughput.
121121

122122
This approach combines two Visual Studio project settings:
123123

124-
- **Scan Sources for Module Dependencies** causes the build system to call the compiler to ensure that all imported modules and header units are built before compiling the files that depend on them. When combined with **Translate Includes to Imports**, header files included in your source, that are also specified in a [`header-units.json`](./reference/header-unit-json-reference.md) file in the same directory as the header file, are compiled into header units.
124+
- **Scan Sources for Module Dependencies** causes the build system to call the compiler to ensure that all imported modules and header units are built before compiling the files that depend on them. When combined with **Translate Includes to Imports**, any header files included in your source that are also specified in a [`header-units.json`](./reference/header-unit-json-reference.md) file in the same directory as the header file, are compiled into header units.
125125
- **Translate Includes to Imports** treats a header file as an `import` if the `#include` refers to a header file that can be compiled as a header unit (as specified in a `header-units.json` file), and a compiled header unit is available for the header file. Otherwise, the header file is treated as a normal `#include`. The [`header-units.json`](./reference/header-unit-json-reference.md) file is used to automatically build header units for each `#include` without symbol duplication.
126126

127127
You can turn on these settings in the properties for your project. To do so, right-click the project in the **Solution Explorer** and choose **Properties**. Then choose **Configuration Properties** > **C/C++** > **General**.
@@ -132,7 +132,7 @@ You can turn on these settings in the properties for your project. To do so, rig
132132

133133
These settings work together to automatically build and import header units under these conditions:
134134

135-
- **Scan Sources for Module Dependencies** scans your sources for files, and their dependencies, that can be treated as header units. Files that have the extension `.ixx`, and those which have their **File properties** > **C/C++** > **Compile As** property set to **Compile as C++ Header Unit (/export)**, are always scanned regardless of this setting. The compiler also looks for `import` statements to identify header unit dependencies. If `/translateInclude` is specified, the compiler also scans for `#include` directives that are also specified in a `header-units.json` file to treat as header units. A dependency graph is built of all the modules and header units in your project.
135+
- **Scan Sources for Module Dependencies** scans your sources for the files and their dependencies that can be treated as header units. Files that have the extension `.ixx`, and files that have their **File properties** > **C/C++** > **Compile As** property set to **Compile as C++ Header Unit (/export)**, are always scanned regardless of this setting. The compiler also looks for `import` statements to identify header unit dependencies. If `/translateInclude` is specified, the compiler also scans for `#include` directives that are also specified in a `header-units.json` file to treat as header units. A dependency graph is built of all the modules and header units in your project.
136136
- **Translate Includes to Imports** When the compiler encounters an `#include` statement, and a matching header unit file (`.ifc`) exists for the specified header file, the compiler imports the header unit instead of treating the header file as an `#include`. When combined with **Scan for dependencies**, the compiler finds all of the header files that can be compiled into header units. An allowlist is consulted by the compiler to decide which header files can compile into header units. This list is stored in a [`header-units.json`](./reference/header-unit-json-reference.md) file that must be in the same directory as the included file. You can see an example of a `header-units.json` file under the installation directory for Visual Studio. For example, `%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.30.30705\include\header-units.json` is used by the compiler to determine whether a Standard Template Library header can be compiled into a header unit. This functionality exists to serve as a bridge with legacy code to get some benefits of header units.
137137

138138
The `header-units.json` file serves two purposes. In addition to specifying which header files can be compiled into header units, it minimizes duplicated symbols to increase build throughput. For more information about symbol duplication, see [C++ header-units.json reference](reference/header-unit-json-reference.md#preventing-duplicated-symbols).
@@ -145,9 +145,9 @@ For an example of how this technique is used to import STL header files as heade
145145

146146
## Preprocessor implications
147147

148-
The standard C99/C++11 conforming preprocessor is required to create and use header units. The compiler enables the new C99/C++11 conforming preprocessor when compiling header units by implicitly adding [`/Zc:preprocessor`](/cpp/build/reference/zc-preprocessor) to the command line whenever any form of `/exportHeader` is used. Attempting to turn it off will result in a compilation error.
148+
The standard C99/C++11 conforming preprocessor is required to create and use header units. The compiler enables the new C99/C++11 conforming preprocessor when compiling header units by implicitly adding [`/Zc:preprocessor`](./reference/zc-preprocessor.md) to the command line whenever any form of `/exportHeader` is used. Attempting to turn it off will result in a compilation error.
149149

150-
Enabling the new preprocessor affects the processing of variadic macros. For more information, see the [Variadic macros](/cpp/preprocessor/variadic-macros#remarks) remarks section.
150+
Enabling the new preprocessor affects the processing of variadic macros. For more information, see the [Variadic macros](../preprocessor/variadic-macros.md#remarks) remarks section.
151151

152152
## See also
153153

docs/c-runtime-library/reference/vsnprintf-s-vsnprintf-s-vsnprintf-s-l-vsnwprintf-s-vsnwprintf-s-l.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: vsnprintf_s, _vsnprintf_s, _vsnprintf_s_l, _vsnwprintf_s, _vsnwprintf_s_l"
33
title: "vsnprintf_s, _vsnprintf_s, _vsnprintf_s_l, _vsnwprintf_s, _vsnwprintf_s_l"
4-
ms.date: 09/09/2022
4+
ms.date: 09/29/2022
55
api_name: ["_vsnwprintf_s", "_vsnwprintf_s_l", "_vsnprintf_s", "vsnprintf_s", "_vsnprintf_s_l"]
66
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ntdll.dll", "ucrtbase.dll", "ntoskrnl.exe"]
77
api_type: ["DLLExport"]
@@ -135,8 +135,8 @@ The versions of these functions with the **`_l`** suffix are identical except th
135135
136136
In C++, using these functions is simplified by template overloads; the overloads can infer buffer length automatically (eliminating the need to specify a size argument) and they can automatically replace older, non-secure functions with their newer, secure counterparts. For more information, see [Secure Template Overloads](../../c-runtime-library/secure-template-overloads.md).
137137

138-
> [!Tip]
139-
> If you get an undefined external `_vsnprintf_s` error and are using the Universal C Runtime, add `legacy_stdio_definitions.lib` to the set of libraries to link with. The Universal C Runtime doesn't export this function directly and is instead defined inline in `<stdio.h>`. For more information, see [Overview of potential upgrade issues](/cpp/porting/overview-of-potential-upgrade-issues-visual-cpp.md#libraries) and [Visual Studio 2015 Conformance Changes](/cpp/porting/visual-cpp-change-history-2003-2015.md#stdio_and_conio).
138+
> [!TIP]
139+
> If you get an undefined external `_vsnprintf_s` error and are using the Universal C Runtime, add `legacy_stdio_definitions.lib` to the set of libraries to link. The Universal C Runtime doesn't export this function directly and is instead defined inline in `<stdio.h>`. For more information, see [Overview of potential upgrade issues](../../porting/overview-of-potential-upgrade-issues-visual-cpp.md#libraries) and [Visual Studio 2015 Conformance Changes](../../porting/visual-cpp-change-history-2003-2015.md#stdio_and_conio).
140140
141141
### Generic-Text Routine Mappings
142142

0 commit comments

Comments
 (0)