You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp/align-cpp.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ For information about how to return a value of type `size_t` that is the alignme
27
27
28
28
You can use `__declspec(align(#))` when you define a **`struct`**, **`union`**, or **`class`**, or when you declare a variable.
29
29
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.
31
31
32
32
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.
Copy file name to clipboardExpand all lines: docs/cpp/alignas-specifier.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ alignas(pack...)
21
21
22
22
You can use **`alignas`** specifier on a **`struct`**, **`class`**, **`union`**, or variable declaration.
23
23
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.
25
25
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.
27
27
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:
29
29
30
30
```cpp
31
31
structalignas(8) S1
@@ -36,7 +36,7 @@ struct alignas(8) S1
36
36
static_assert(alignof(S1) == 8, "alignof(S1) should be 8");
37
37
```
38
38
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.
40
40
41
41
The following example shows how to use `alignas` with a user-defined type:
42
42
@@ -71,7 +71,7 @@ struct alignas(double) S2
71
71
static_assert(alignof(S2) == alignof(double), "alignof(S2) should be equivalent to alignof(double)");
72
72
```
73
73
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.
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
+
89
90
The declaration and definition of user-defined types must have the same alignment value.
0 commit comments