Skip to content

Commit 0524ef8

Browse files
TylerMSFTTylerMSFT
authored andcommitted
edits
1 parent d9c9cd0 commit 0524ef8

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

docs/cpp/align-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ For information about how to return a value of type `size_t` that is the alignme
2727

2828
You can use `__declspec(align(#))` when you define a **`struct`**, **`union`**, or **`class`**, or when you declare a variable.
2929

30-
The compiler doesn't guarantee, or attempt to preserve, the alignment attribute of data during a copy or data transform operation. For example, [`memcpy`](../c-runtime-library/reference/memcpy-wmemcpy.md) can copy a struct declared with `__declspec(align(#))` to any location. Ordinary allocators (for example, [`malloc`](../c-runtime-library/reference/malloc.md), C++ [`operator new`](new-operator-cpp.md), and the Win32 allocators) typically return memory that isn't sufficiently aligned for `__declspec(align(#))` structures or arrays of structures. To guarantee that the destination of a copy or data transformation operation is correctly aligned, use [`_aligned_malloc`](../c-runtime-library/reference/aligned-malloc.md). Or, write your own allocator.
30+
The compiler doesn't guarantee, or attempt to preserve, the alignment attribute of data during a copy or data transform operation. For example, [`memcpy`](../c-runtime-library/reference/memcpy-wmemcpy.md) can copy a struct declared with `__declspec(align(#))` to any location. Ordinary allocators (for example, [`malloc`](../c-runtime-library/reference/malloc.md), C++ [`operator new`](new-operator-cpp.md), and the Win32 allocators) typically return memory that isn't aligned for `__declspec(align(#))` structures or arrays of structures. To guarantee that the destination of a copy or data transformation operation is correctly aligned, use [`_aligned_malloc`](../c-runtime-library/reference/aligned-malloc.md). Or, write your own allocator.
3131

3232
You can't specify alignment for function parameters. When you pass data that has an alignment attribute by value on the stack, the calling convention controls its alignment. If data alignment is important in the called function, copy the parameter into correctly aligned memory before use.
3333

docs/cpp/alignas-specifier.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ alignas(pack...)
2121

2222
You can use **`alignas`** specifier on a **`struct`**, **`class`**, **`union`**, or variable declaration.
2323

24-
For `alignas(expression)`, the expression must be an integral constant expression that is 0 or a power of 2 (1, 2, 4, 8, 16, 32, 64...). All other expressions are ill-formed.
24+
For `alignas(expression)`, the expression must be an integral constant expression that is 0 or a power of 2 (1, 2, 4, 8, 16, ...). All other expressions are ill-formed.
2525

26-
Prefer **`alignas`** over [`__declspec(align(#))`](align-cpp.md) for code portability.
26+
Use **`alignas`** instead of [`__declspec(align(#))`](align-cpp.md) for code portability.
2727

28-
A common use of `alignas` is to control the alignment of a user-defined type as shown in the following example:
28+
A common use of `alignas` is to control the alignment of a user-defined type, as shown in the following example:
2929

3030
```cpp
3131
struct alignas(8) S1
@@ -36,7 +36,7 @@ struct alignas(8) S1
3636
static_assert(alignof(S1) == 8, "alignof(S1) should be 8");
3737
```
3838

39-
When multiple **`alignas`** are applied to the same declaration, the one with the largest value is used. When the **`alignas`** value is `0`, **`alignas`** is ignored.
39+
When multiple **`alignas`** are applied to the same declaration, the one with the largest value is used. An **`alignas`** value of `0` is ignored.
4040

4141
The following example shows how to use `alignas` with a user-defined type:
4242

@@ -71,7 +71,7 @@ struct alignas(double) S2
7171
static_assert(alignof(S2) == alignof(double), "alignof(S2) should be equivalent to alignof(double)");
7272
```
7373

74-
A template parameter pack (`alignas ( pack... )`) can also be used as the alignment value. The largest alignment of all the elements in the pack is used.
74+
A template parameter pack (`alignas (pack...)`) can be used for the alignment value. The largest alignment value of all the elements in the pack is used.
7575

7676
```cpp
7777
template <typename... Ts>
@@ -86,6 +86,7 @@ static_assert(alignof(C2<int, float, double>) == 8, "alignof(C2<int, float, doub
8686
```
8787

8888
If multiple **`alignas`** are applied, the resulting alignment is the largest of all the **`alignas`** values, and can't be less than the natural alignment of the type it's applied to.
89+
8990
The declaration and definition of user-defined types must have the same alignment value.
9091

9192
```cpp

0 commit comments

Comments
 (0)