Skip to content

Commit 2052907

Browse files
learn-build-service-prod[bot]AnjuDelTylerMSFTprmerger-automator[bot]huypub
authored
Resolve syncing conflicts from FromPrivateLiveToMaster to main (#4433)
* rewording ReadString documentation to be more accurate (#4815) * reword nmax parameter wording for ReadString to be more accurate * change suggested directory location * acrolinx * incorp review * fix path * improve path * Confirm merge from FromPublicMasterBranch to main to sync with https://github.com/MicrosoftDocs/cpp-docs (branch main) (#4817) * Update vcperf-commands.md (#4375) * Update vcperf-commands.md Update commands according to https://github.com/microsoft/vcperf#command-line-reference * Update vcperf-commands.md * Update with grammar fixes for i18n --------- Co-authored-by: Colin Robertson <[email protected]> * Update tutorial-import-stl-named-module.md (#4429) * Update tutorial-import-stl-named-module.md The Title of the document doesn't reveal that this procedure is only for a command line case. Suggest altering the titles to reflect this and improve clarity for readers searching for module documentation. * Update tutorial-import-stl-named-module.md Changed the capitalization at Microsoft's request. --------- Co-authored-by: huypub <[email protected]> Co-authored-by: learn-build-service-prod[bot] <113403604+learn-build-service-prod[bot]@users.noreply.github.com> Co-authored-by: Nelson Daniel Troncoso <[email protected]> Co-authored-by: Colin Robertson <[email protected]> Co-authored-by: Centurion Maximus <[email protected]> * fix casing and wording * acrolinx --------- Co-authored-by: Anju del Moral Gonzalez <[email protected]> Co-authored-by: TylerMSFT <[email protected]> Co-authored-by: prmerger-automator[bot] <40007230+prmerger-automator[bot]@users.noreply.github.com> Co-authored-by: learn-build-service-prod[bot] <113403604+learn-build-service-prod[bot]@users.noreply.github.com> Co-authored-by: huypub <[email protected]> Co-authored-by: Nelson Daniel Troncoso <[email protected]> Co-authored-by: Colin Robertson <[email protected]> Co-authored-by: Centurion Maximus <[email protected]> Co-authored-by: Jak Koke <[email protected]>
1 parent eebd25b commit 2052907

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

docs/cpp/tutorial-import-stl-named-module.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
22
title: "Tutorial: Import the standard library (STL) using modules from the command line (C++)"
3-
ms.date: 12/02/2022
3+
ms.date: 2/23/2023
44
ms.topic: "tutorial"
55
author: "tylermsft"
66
ms.author: "twhitney"
77
helpviewer_keywords: ["modules [C++]", "modules [C++]", "named modules [C++], import standard library (STL) using named modules"]
8-
description: Learn how to import the C++ standard library (STL) using modules
8+
description: Learn how to import the C++ standard library (STL) using modules from the command line
99
---
10-
# Tutorial: Import the C++ standard library using modules from the Command Line
10+
11+
# Tutorial: Import the C++ standard library using modules from the command line
1112

1213
Learn how to import the C++ standard library using C++ library modules. This is significantly faster to compile and more robust than using header files or header units or precompiled headers (PCH).
1314

@@ -32,35 +33,35 @@ It's now possible to import the standard library as a module instead of as a tan
3233

3334
The C++23 standard library introduces two named modules: `std` and `std.compat`.
3435

35-
- `std` exports the declarations and names defined in the C++ standard library that are in namespace `std` such as `std::vector` and `std::sort`. It also exports the contents of C wrapper headers such as `<cmath>`, `<cstdio>`, `<cstdlib>` that provide `std::byte`, `std::printf()`, and so on. The C functions defined in the *global namespace* such as `::printf()` and `::fopen` aren't exported. This improves the situation where previously including a C wrapper header like `<cstdio>` which provides `std::` qualified versions of the C runtime functions *also* included the actual C header, like `stdio.h`, which meant the C global namespace versions were also brought in. This is no longer a problem if you import `std`.
36-
- `std.compat` exports everything in `std`, and adds the global namespace counterparts of the C runtime such as `::printf`, `::fopen`, `::size_t`, `::strlen`, and so on. This module makes it easier when working with a codebase that refers to many C runtime functions/types in the global namespace.
36+
- `std` exports the declarations and names defined in the C++ standard library namespace `std` such as `std::vector` and `std::sort`. It also exports the contents of C wrapper headers such as `<cstdio>` and `<cstdlib>`, which provide functions like `std::printf()`. C functions defined in the *global namespace*, such as `::printf()`, aren't exported. This improves the situation where including a C wrapper header like `<cstdio>` *also* included C header files like `stdio.h`, which brought in the C global namespace versions. This is no longer a problem if you import `std`.
37+
- `std.compat` exports everything in `std` and adds the global namespace counterparts of the C runtime such as `::printf`, `::fopen`, `::size_t`, `::strlen`, and so on. This module makes it easier to work with a codebase that refers to many C runtime functions/types in the global namespace.
3738

3839
The compiler imports the entire standard library when you use `import std;` or `import std.compat;` and does it faster than bringing in a single header file. That is, it's faster to bring in the entire standard library with `import std;` (or `import std.compat`) than it's to `#include <vector>`, for example.
3940

4041
Because named modules don't expose macros, macros like `assert`, `errno`, `offsetof`, `va_arg`, and others aren't available when you import `std` or `std.compat`. See [Standard library named module considerations](#standard-library-named-module-considerations) for workarounds.
4142

4243
## A little about C++ modules
4344

44-
Header files are how declarations and definitions have been shared between source files in C++. Prior to standard library modules, you'd include the part of the standard library you needed with a directive like `#include <vector>`. Header files are fragile and difficult to compose because their semantics may change depending on the order you include them, or whether certain macros are or aren't defined. They also slow compilation because they have to be reprocessed by every source file that includes them.
45+
Header files are how declarations and definitions have been shared between source files in C++. Prior to standard library modules, you'd include the part of the standard library you needed with a directive like `#include <vector>`. Header files are fragile and difficult to compose because their semantics may change depending on the order you include them, or whether certain macros are or aren't defined. They also slow compilation because they're reprocessed by every source file that includes them.
4546

4647
C++20 introduces a modern alternative called *modules*. In C++23, we were able to capitalize on module support to introduce named modules for the standard library.
4748

48-
Like header files, modules allow you to share declarations and definitions across source files. But unlike header files, modules aren't fragile and are easier to compose because their semantics don't change due to macro definitions or the order in which you import them. The compiler can process modules significantly faster than it can process `#include` files, and uses less memory at compile time as well. Macro definitions defined in a named module aren't exposed, nor are private implementation details.
49+
Like header files, modules allow you to share declarations and definitions across source files. But unlike header files, modules aren't fragile and are easier to compose because their semantics don't change due to macro definitions or the order in which you import them. The compiler can process modules significantly faster than it can process `#include` files, and uses less memory at compile time as well. Named modules don't expose macro definitions or private implementation details.
4950

5051
For in depth information about modules, see [Overview of modules in C++](modules-cpp.md) That article also discusses consuming the C++ standard library as modules, but uses an older and experimental way of doing it.
5152

5253
This article demonstrates the new and best way to consume the standard library. For more information about alternative ways to consume the standard library, see [Compare header units, modules, and precompiled headers](../build/compare-inclusion-methods.md).
5354

5455
## Import the standard library with `std`
5556

56-
The following examples demonstrates how to consume the standard library as a module using the command line compiler. The Visual Studio IDE experience for importing the standard library as a module is still being implemented.
57+
The following examples demonstrate how to consume the standard library as a module using the command line compiler. The Visual Studio IDE experience for importing the standard library as a module is being implemented.
5758

58-
The standard library is imported into your application with the statement `import std;` or `import std.compat;`. But first, you must compile the standard library named modules. The following steps demonstrate how.
59+
The statement `import std;` or `import std.compat;` imports the standard library into your application. But first, you must compile the standard library named modules. The following steps demonstrate how.
5960

6061
### Example: `std`
6162

6263
1. Open a x86 Native Tools Command Prompt for VS: from the Windows **Start** menu, type *x86 native* and the prompt should appear in the list of apps. Ensure that the prompt is for Visual Studio 2022 preview version 17.5 or above. You'll get errors if you use the wrong version of the prompt. The examples used in this tutorial are for the CMD shell. If you use PowerShell, substitute `"$Env:VCToolsInstallDir\modules\std.ixx"` for `"%VCToolsInstallDir\modules\std.ixx"`.
63-
1. Create a directory such as `C:\STLModules`, and make it the current directory.
64+
1. Create a directory, such as `%USERPROFILE%\source\repos\STLModules`, and make it the current directory. If you choose a directory that you don't have write access to, you'll get errors such as not being able to open the output file `std.ifc`.
6465
1. Compile the `std` named module with the following command:
6566

6667
```dos
@@ -71,9 +72,9 @@ The standard library is imported into your application with the statement `impor
7172
7273
You should compile the `std` named module using the same compiler settings that you intend to use with the code that imports it. If you have a multi-project solution, you can compile the standard library named module once, and then refer to it from all of your projects by using the [`/reference`](../build/reference/module-reference.md) compiler option.
7374
74-
Using the compiler command above, the compiler outputs two files:
75+
Using the previous compiler command, the compiler outputs two files:
7576
- `std.ifc` is the compiled binary representation of the named module interface that the compiler consults to process the `import std;` statement. This is a compile-time only artifact. It doesn't ship with your application.
76-
- `std.obj` contains the implementation of the named module. Add `std.obj` to the command line when you compile the sample app so that functionality you use from the standard library can be statically linked into your application.
77+
- `std.obj` contains the implementation of the named module. Add `std.obj` to the command line when you compile the sample app to statically link the functionality you use from the standard library into your application.
7778
7879
The key command-line switches in this example are:
7980
@@ -131,14 +132,14 @@ The standard library is imported into your application with the statement `impor
131132
132133
The C++ standard library includes the ISO C standard library. The `std.compat` module provides all of the functionality of the `std` module like `std::vector`, `std::cout`, `std::printf`, `std::scanf`, and so on. But it also provides the global namespace versions of these functions such as `::printf`, `::scanf`, `::fopoen`, `::size_t`, and so on.
133134
134-
The `std.compat` named module is a compatibility layer provided to ease migrating existing code that refers to C runtime functions in the global namespace. If you want to avoid adding names to the global namespace, use `import std;`. If you need to ease migrating a codebase that uses many unqualified (that is, global namespace) C runtime functions, use `import std.compat;`. This provides the global namespace C runtime names so that you don't have to qualify all the global name mentions with `std::`. If you don't have any existing code that uses the global namespace C runtime functions, then you don't need to use `import std.compat;`. If you only call a few C runtime functions in your code, it may be better to use `import std;` and qualify the few global namespace C runtime names that need it with `std::`, for example, `std::printf()`. You'll know that you should consider using `import std.compat;` if you see an error like `error C3861: 'printf': identifier not found` when you try to compile your code.
135+
The `std.compat` named module is a compatibility layer provided to ease migrating existing code that refers to C runtime functions in the global namespace. If you want to avoid adding names to the global namespace, use `import std;`. If you need to ease migrating a codebase that uses many unqualified (that is, global namespace) C runtime functions, use `import std.compat;`. This provides the global namespace C runtime names so that you don't have to qualify all the global name mentions with `std::`. If you don't have any existing code that uses the global namespace C runtime functions, then you don't need to use `import std.compat;`. If you only call a few C runtime functions in your code, it may be better to use `import std;` and qualify the few global namespace C runtime names that need it with `std::`, for example, `std::printf()`. If you see an error like `error C3861: 'printf': identifier not found` when you try to compile your code, consider using `import std.compat;` to import the global namespace C runtime functions.
135136
136137
### Example: `std.compat`
137138
138139
Before you can use `import std.compat;` in your code, you must compile the named module `std.compat.ixx`. The steps are similar to for building the `std` named module. The steps include building the `std` named module first because `std.compat` depends on it:
139140
140-
1. Open a Native Tools Command Prompt for VS: from the Windows **Start** menu, type *x86 native* and the prompt should appear in the list of apps. Ensure that the prompt is for Visual Studio 2022 preview version 17.5 or above. If you use the wrong version of the prompt, you'll get compiler errors.
141-
1. Create a directory to try this example, such as `C:\STLCompatModules`, and make it the current directory.
141+
1. Open a Native Tools Command Prompt for VS: from the Windows **Start** menu, type *x86 native* and the prompt should appear in the list of apps. Ensure that the prompt is for Visual Studio 2022 preview version 17.5 or above. You'll get compiler errors if you use the wrong version of the prompt.
142+
1. Create a directory to try this example, such as `%USERPROFILE%\source\repos\STLModules`, and make it the current directory. If you choose a directory that you don't have write access to, you'll get errors such as not being able to open the output file `std.ifc`.
142143
1. Compile the `std` and `std.compat` named modules with the following command:
143144
144145
```dos
@@ -153,7 +154,7 @@ Before you can use `import std.compat;` in your code, you must compile the named
153154
- `std.ifc` is the compiled binary named module interface that the compiler consults to process the `import std;` statement. The compiler also consults `std.ifc` to process `import std.compat;` because `std.compat` builds on `std`. This is a compile-time only artifact. It doesn't ship with your application.
154155
- `std.obj` contains the implementation of the standard library.
155156
- `std.compat.ifc` is the compiled binary named module interface that the compiler consults to process the `import std.compat;` statement. This is a compile-time only artifact. It doesn't ship with your application.
156-
- `std.compat.obj` contains implementation. However, most of the implementation is provided by `std.obj`. Add `std.obj` to the command line as well when you compile the sample app so that the functionality you use from the standard library can be statically linked into your application.
157+
- `std.compat.obj` contains implementation. However, most of the implementation is provided by `std.obj`. Add `std.obj` to the command line when you compile the sample app to statically link the functionality that you use from the standard library into your application.
157158
158159
1. To try out importing the `std.compat` library, create a file named `stdCompatExample.cpp` with the following content:
159160
@@ -192,7 +193,7 @@ Before you can use `import std.compat;` in your code, you must compile the named
192193
193194
I've shown them as separate steps in this tutorial because you only need to build the standard library named modules once, and then you can refer to them from your project, or from multiple projects. But it may be convenient to build them all at once.
194195
195-
The compiler command above produces an executable named `stdCompatExample.exe`. When you run it, it produces the following output:
196+
The previous compiler command produces an executable named `stdCompatExample.exe`. When you run it, it produces the following output:
196197
197198
```output
198199
Import std.compat to get global names like printf()

docs/mfc/reference/cstdiofile-class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ virtual BOOL ReadString(CString& rString);
181181
Specifies a pointer to a user-supplied buffer that will receive a null-terminated text string.
182182

183183
*`nMax`*<br/>
184-
Specifies the maximum number of characters to read, not counting the terminating null character.
184+
Specifies the maximum number of characters to write into the *`lpsz`* buffer, including the terminating null.
185185

186186
*`rString`*<br/>
187187
A reference to a `CString` object that will contain the string when the function returns.

0 commit comments

Comments
 (0)