Skip to content

Commit 4a6fe1b

Browse files
author
3836425+corob-msft@users.noreply.github.com
committed
Updates for cpp-docs 3700 3703
1 parent 3df3daf commit 4a6fe1b

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

docs/assembler/inline/masm-macro-directives-in-inline-assembly.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ ms.assetid: 83643a09-1699-40a8-8ef2-13502bc4ac2c
99

1010
**Microsoft Specific**
1111

12-
The inline assembler is not a macro assembler. You cannot use MASM macro directives (**MACRO**, `REPT`, **IRC**, `IRP`, and `ENDM`) or macro operators (**<>**, **!**, **&**, `%`, and `.TYPE`). An **`__asm`** block can use C preprocessor directives, however. See [Using C or C++ in __asm Blocks](../../assembler/inline/using-c-or-cpp-in-asm-blocks.md) for more information.
12+
The inline assembler isn't a macro assembler. You can't use MASM macro directives (`MACRO`, `REPT`, `IRC`, `IRP`, and `ENDM`) or macro operators (**`<>`**, **`!`**, **`&`**, **`%`**, and `.TYPE`). An **`__asm`** block can use C preprocessor directives, however. See [Using C or C++ in `__asm` blocks](../../assembler/inline/using-c-or-cpp-in-asm-blocks.md) for more information.
1313

1414
**END Microsoft Specific**
1515

1616
## See also
1717

18-
[Using Assembly Language in __asm Blocks](../../assembler/inline/using-assembly-language-in-asm-blocks.md)<br/>
18+
[Using assembly language in `__asm` blocks](../../assembler/inline/using-assembly-language-in-asm-blocks.md)

docs/assembler/inline/writing-functions-with-inline-assembly.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
---
2-
description: "Learn more about: Writing Functions with Inline Assembly"
3-
title: "Writing Functions with Inline Assembly"
4-
ms.date: "08/30/2018"
2+
description: "Learn more about: Writing functions with inline assembly"
3+
title: "Writing functions with inline assembly"
4+
ms.date: 02/11/2022
55
helpviewer_keywords: ["functions [C++], inline assembly", "inline assembly [C++], writing functions", "assembler [C++], writing functions", "__asm keyword [C++], in functions"]
66
ms.assetid: b5df8a04-fdc7-4622-8c9e-e4b618927497
77
---
8-
# Writing Functions with Inline Assembly
8+
# Writing functions with inline assembly
99

1010
**Microsoft Specific**
1111

12-
If you write a function with inline assembly code, it's easy to pass arguments to the function and return a value from it. The following examples compare a function first written for a separate assembler and then rewritten for the inline assembler. The function, called `power2`, receives two parameters, multiplying the first parameter by 2 to the power of the second parameter. Written for a separate assembler, the function might look like this:
12+
> [!NOTE]
13+
> Inline assembly is only available for x86 targets. For similar functionality in x64 or ARM64 code, use [compiler intrinsics](../../intrinsics/compiler-intrinsics.md).
14+
15+
If you write a function with inline assembly code, it's easy to pass arguments to the function and return a value from it. The following examples compare a function first written for a separate assembler and then rewritten for the inline assembler. The function, called `power2`, receives two parameters, multiplying the first parameter by 2 to the power of the second parameter. As a separate assembler file, the function might look like this:
1316

1417
```asm
15-
; POWER.ASM
16-
; Compute the power of an integer
17-
;
18-
PUBLIC _power2
19-
_TEXT SEGMENT WORD PUBLIC 'CODE'
18+
; power2.asm
19+
; x86 code for C interop
20+
; Command line: ml /c /Cx /W3 /WX power2.asm
21+
.686P
22+
.XMM
23+
.MODEL flat
24+
25+
PUBLIC _power2
26+
; int power2(int num, int power);
27+
; computes num x 2^power
28+
_TEXT SEGMENT
2029
_power2 PROC
21-
22-
push ebp ; Save EBP
23-
mov ebp, esp ; Move ESP into EBP so we can refer
24-
; to arguments on the stack
25-
mov eax, [ebp+4] ; Get first argument
26-
mov ecx, [ebp+6] ; Get second argument
27-
shl eax, cl ; EAX = EAX * ( 2 ^ CL )
28-
pop ebp ; Restore EBP
29-
ret ; Return with sum in EAX
30-
30+
push ebp ; save EBP
31+
mov ebp, esp ; Move ESP into EBP so we can refer
32+
; to arguments on the stack
33+
mov eax, [ebp+8] ; load first argument
34+
mov ecx, [ebp+12] ; load second argument
35+
shl eax, cl ; compute result in EAX
36+
pop ebp ; restore EBP
37+
ret
3138
_power2 ENDP
3239
_TEXT ENDS
33-
END
40+
END
3441
```
3542

36-
Since it's written for a separate assembler, the function requires a separate source file and assembly and link steps. C and C++ function arguments are usually passed on the stack, so this version of the `power2` function accesses its arguments by their positions on the stack. (Note that the **MODEL** directive, available in MASM and some other assemblers, also allows you to access stack arguments and local stack variables by name.)
43+
Since it's written as a separate assembler file, the function requires separate assembly and link steps. C and C++ function arguments are usually passed on the stack, so this version of the `power2` function accesses its arguments by their positions on the stack. (The **`MODEL`** directive, available in MASM and some other assemblers, also allows you to access stack arguments and local stack variables by name.)
3744

3845
## Example
3946

@@ -67,10 +74,10 @@ int power2( int num, int power )
6774
6875
The inline version of the `power2` function refers to its arguments by name and appears in the same source file as the rest of the program. This version also requires fewer assembly instructions.
6976
70-
Because the inline version of `power2` doesn't execute a C **`return`** statement, it causes a harmless warning if you compile at warning level 2 or higher. The function does return a value, but the compiler cannot tell that in the absence of a **`return`** statement. You can use [#pragma warning](../../preprocessor/warning.md) to disable the generation of this warning.
77+
Because the inline version of `power2` doesn't execute a C **`return`** statement, it causes a harmless warning if you compile at warning level 2 or higher. The function does return a value, but the compiler can't tell it does in the absence of a **`return`** statement. You can use [`#pragma warning`](../../preprocessor/warning.md) to disable the generation of this warning.
7178
7279
**END Microsoft Specific**
7380
7481
## See also
7582
76-
[Using C or C++ in __asm Blocks](../../assembler/inline/using-c-or-cpp-in-asm-blocks.md)<br/>
83+
[Using C or C++ in `__asm` Blocks](../../assembler/inline/using-c-or-cpp-in-asm-blocks.md)
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
---
2-
description: "Learn more about: Copy Constructors and Copy Assignment Operators (C++)"
3-
title: "Copy Constructors and Copy Assignment Operators (C++)"
4-
ms.date: "11/04/2016"
2+
description: "Learn more about: Copy constructors and copy assignment operators (C++)"
3+
title: "Copy constructors and copy assignment operators (C++)"
4+
ms.date: 02/11/2022
55
helpviewer_keywords: ["= operator [C++], copying objects", "assignment statements [C++], copying objects", "assignment operators [C++], for copying objects", "objects [C++], copying", "initializing objects, by copying objects", "copying objects", "assigning values to copy objects"]
66
ms.assetid: a94fe1f9-0289-4fb9-8633-77c654002c0d
77
---
8-
# Copy Constructors and Copy Assignment Operators (C++)
8+
# Copy constructors and copy assignment operators (C++)
99

1010
> [!NOTE]
1111
> Starting in C++11, two kinds of assignment are supported in the language: *copy assignment* and *move assignment*. In this article "assignment" means copy assignment unless explicitly stated otherwise. For information about move assignment, see [Move Constructors and Move Assignment Operators (C++)](move-constructors-and-move-assignment-operators-cpp.md).
1212
>
1313
> Both the assignment operation and the initialization operation cause objects to be copied.
1414
15-
- **Assignment**: When one object's value is assigned to another object, the first object is copied to the second object. Therefore,
15+
- **Assignment**: When one object's value is assigned to another object, the first object is copied to the second object. So, this code copies the value of `b` into `a`:
1616

1717
```cpp
1818
Point a, b;
1919
...
2020
a = b;
2121
```
2222

23-
causes the value of `b` to be copied to `a`.
24-
25-
- **Initialization**: Initialization occurs when a new object is declared, when arguments are passed to functions by value, or when values are returned from functions by value.
23+
- **Initialization**: Initialization occurs when you declare a new object, when you pass function arguments by value, or when you return by value from a function.
2624

2725
You can define the semantics of "copy" for objects of class type. For example, consider this code:
2826

@@ -33,15 +31,15 @@ b.Open( "FILE2.DAT" );
3331
b = a;
3432
```
3533

36-
The preceding code could mean "copy the contents of FILE1.DAT to FILE2.DAT" or it could mean "ignore FILE2.DAT and make `b` a second handle to FILE1.DAT." You must attach appropriate copying semantics to each class, as follows.
34+
The preceding code could mean "copy the contents of FILE1.DAT to FILE2.DAT" or it could mean "ignore FILE2.DAT and make `b` a second handle to FILE1.DAT." You must attach appropriate copying semantics to each class, as follows:
3735

38-
- By using the assignment operator **operator=** together with a reference to the class type as the return type and the parameter that is passed by **`const`** reference—for example `ClassName& operator=(const ClassName& x);`.
36+
- Use an assignment operator **`operator=`** that returns a reference to the class type and takes one parameter that's passed by **`const`** reference—for example `ClassName& operator=(const ClassName& x);`.
3937

40-
- By using the copy constructor.
38+
- Use the copy constructor.
4139

42-
If you do not declare a copy constructor, the compiler generates a member-wise copy constructor for you. If you do not declare a copy assignment operator, the compiler generates a member-wise copy assignment operator for you. Declaring a copy constructor does not suppress the compiler-generated copy assignment operator, nor vice versa. If you implement either one, we recommend that you also implement the other one so that the meaning of the code is clear.
40+
If you don't declare a copy constructor, the compiler generates a member-wise copy constructor for you. Similarly, if you don't declare a copy assignment operator, the compiler generates a member-wise copy assignment operator for you. Declaring a copy constructor doesn't suppress the compiler-generated copy assignment operator, and vice-versa. If you implement either one, we recommend that you implement the other one, too. When you implement both, the meaning of the code is clear.
4341

44-
The copy constructor takes an argument of type <em>class-name</em><strong>&</strong>, where *class-name* is the name of the class for which the constructor is defined. For example:
42+
The copy constructor takes an argument of type `ClassName&`, where *`ClassName`* is the name of the class. For example:
4543

4644
```cpp
4745
// spec1_copying_class_objects.cpp
@@ -58,19 +56,19 @@ int main()
5856
```
5957

6058
> [!NOTE]
61-
> Make the type of the copy constructor's argument **`const`** <em>class-name</em><strong>&</strong> whenever possible. This prevents the copy constructor from accidentally changing the object from which it is copying. It also enables copying from **`const`** objects.
59+
> Make the type of the copy constructor's argument `const ClassName&` whenever possible. This prevents the copy constructor from accidentally changing the copied object. It also lets you copy from **`const`** objects.
6260
6361
## Compiler generated copy constructors
6462
6563
Compiler-generated copy constructors, like user-defined copy constructors, have a single argument of type "reference to *class-name*." An exception is when all base classes and member classes have copy constructors declared as taking a single argument of type **`const`** <em>class-name</em><strong>&</strong>. In such a case, the compiler-generated copy constructor's argument is also **`const`**.
6664

67-
When the argument type to the copy constructor is not **`const`**, initialization by copying a **`const`** object generates an error. The reverse is not true: If the argument is **`const`**, you can initialize by copying an object that is not **`const`**.
65+
When the argument type to the copy constructor isn't **`const`**, initialization by copying a **`const`** object generates an error. The reverse isn't true: If the argument is **`const`**, you can initialize by copying an object that's not **`const`**.
6866
69-
Compiler-generated assignment operators follow the same pattern with regard to **const.** They take a single argument of type <em>class-name</em><strong>&</strong> unless the assignment operators in all base and member classes take arguments of type **`const`** <em>class-name</em><strong>&</strong>. In this case, the class's generated assignment operator takes a **`const`** argument.
67+
Compiler-generated assignment operators follow the same pattern for **`const`**. They take a single argument of type `ClassName&` unless the assignment operators in all base and member classes take arguments of type `const ClassName&`. In this case, the generated assignment operator for the class takes a **`const`** argument.
7068
7169
> [!NOTE]
72-
> When virtual base classes are initialized by copy constructors, compiler-generated or user-defined, they are initialized only once: at the point when they are constructed.
70+
> When virtual base classes are initialized by copy constructors, whether compiler-generated or user-defined, they're initialized only once: at the point when they are constructed.
7371

74-
The implications are similar to those of the copy constructor. When the argument type is not **`const`**, assignment from a **`const`** object generates an error. The reverse is not true: If a **`const`** value is assigned to a value that is not **`const`**, the assignment succeeds.
72+
The implications are similar to the copy constructor. When the argument type isn't **`const`**, assignment from a **`const`** object generates an error. The reverse isn't true: If a **`const`** value is assigned to a value that's not **`const`**, the assignment succeeds.
7573
7674
For more information about overloaded assignment operators, see [Assignment](../cpp/assignment.md).

docs/cpp/tutorial-named-modules-cpp.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ So far, we've defined the primary module interface, which exposes the API surfac
182182

183183
## Create a module unit implementation file
184184

185-
Module unit implementation files don't end with an `.ixx` extension. They're normal `.cpp` files. Add a module unit implementation file by creating a source file with a right-click in the **Solution Explorer** on **Source Files**, select **Add** > **New item...** and then select **C++ File (.cpp)**. Give the new file the name `BasicPlane.Figures-Rectangle.cpp`, then select **Add**.
185+
Module unit implementation files don't end with an *`.ixx`* extension. They're normal *`.cpp`* files. Add a module unit implementation file by creating a source file with a right-click in the **Solution Explorer** on **Source Files**, select **Add** > **New item** and then select **C++ File (.cpp)**. Give the new file the name `BasicPlane.Figures-Rectangle.cpp`, then select **Add**.
186186

187-
The naming convention for the module partition's implementation file follows the naming convention for partition. But it has a `.cpp` extension because it's an implementation file.
187+
The naming convention for the module partition's implementation file follows the naming convention for partition. But it has a *`.cpp`* extension because it's an implementation file.
188188

189189
Replace the contents of the `BasicPlane.Figures-Rectangle.cpp` file with:
190190

@@ -297,7 +297,7 @@ Module implementation units belong to a named module. The named module they belo
297297

298298
Module implementation units are useful for breaking up a large module to factor dependencies to get faster build times. This technique is covered briefly in the [Best practices](#module-best-practices) section.
299299

300-
Module implementation unit files have a `.cpp` extension. The basic outline of a module implementation unit file is:
300+
Module implementation unit files have a *`.cpp`* extension. The basic outline of a module implementation unit file is:
301301

302302
```cpp
303303
// optional #include or import statements. These only apply to this file
@@ -351,7 +351,7 @@ A module and the code that imports it must be compiled with the same compiler op
351351
- The name of the file that contains the module primary interface is generally the name of the module. For example, given the module name `BasicPlane.Figures`, the name of the file containing the primary interface would be named `BasicPlane.Figures.ixx`.
352352
- The name of a module partition file is generally `<primary-module-name>-<module-partition-name>` where the name of the module is followed by a hyphen ('-') and then the name of the partition. For example, `BasicPlane.Figures-Rectangle.ixx`
353353

354-
If you're building from the command line and you use this naming convention for module partitions, then you won't have to explicitly add `/reference` for each module partition file. The compiler will look for them automatically based on the name of the module. The name of the compiled partition file (ending with an `.ifc` extension) is generated implicitly from the module name. Consider the module name `BasicPlane.Figures:Rectangle`. The compiler will anticipate that the corresponding compiled partition file for `Rectangle` is named `BasicPlane.Figures-Rectangle.ifc`. The compiler uses this naming scheme to ease using module partitions by automatically finding the interface unit files for partitions.
354+
If you're building from the command line and you use this naming convention for module partitions, then you won't have to explicitly add `/reference` for each module partition file. The compiler will look for them automatically based on the name of the module. The name of the compiled partition file (ending with an *`.ifc`* extension) is generated implicitly from the module name. Consider the module name `BasicPlane.Figures:Rectangle`. The compiler will anticipate that the corresponding compiled partition file for `Rectangle` is named `BasicPlane.Figures-Rectangle.ifc`. The compiler uses this naming scheme to ease using module partitions by automatically finding the interface unit files for partitions.
355355

356356
Or, you can name them using your own convention. But then you'll need to specify corresponding [`/reference`](../build/reference/module-reference.md) arguments to the command-line compiler.
357357

docs/docfx.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
},
155155
"author": {
156156
"index.md": "corob-msft",
157-
"assembler/**.md": "tylermsft",
157+
"assembler/**.md": "corob-msft",
158158
"attributes/**.md": "corob-msft",
159159
"atl/**.md": "tylermsft",
160160
"atl-mfc-shared/**.md": "tylermsft",
@@ -191,7 +191,7 @@
191191
},
192192
"ms.author": {
193193
"index.md": "corob",
194-
"assembler/**.md": "twhitney",
194+
"assembler/**.md": "corob",
195195
"atl/**.md": "twhitney",
196196
"atl-mfc-shared/**.md": "twhitney",
197197
"attributes/**.md": "corob",

0 commit comments

Comments
 (0)