|
1 | 1 | ---
|
2 | 2 | title: "__unaligned | Microsoft Docs"
|
3 | 3 | ms.custom: ""
|
4 |
| -ms.date: "11/04/2016" |
5 |
| -ms.reviewer: "" |
6 |
| -ms.suite: "" |
| 4 | +ms.date: "03/09/2018" |
7 | 5 | ms.technology: ["cpp-language"]
|
8 |
| -ms.tgt_pltfrm: "" |
9 | 6 | ms.topic: "language-reference"
|
10 | 7 | f1_keywords: ["__unaligned_cpp"]
|
11 | 8 | dev_langs: ["C++"]
|
12 | 9 | helpviewer_keywords: ["__unaligned keyword [C++]"]
|
13 | 10 | ms.assetid: 0cd83aad-1840-47e3-ad33-59bfcbe6375b
|
14 |
| -caps.latest.revision: 11 |
15 | 11 | author: "mikeblome"
|
16 | 12 | ms.author: "mblome"
|
17 | 13 | manager: "ghogen"
|
18 | 14 | ms.workload: ["cplusplus"]
|
19 | 15 | ---
|
20 | 16 | # __unaligned
|
21 |
| -When you declare a pointer with the `__unaligned` modifier, the compiler assumes that the pointer addresses data that is not aligned. Consequently, for an application that targets an Itanium Processor Family (IPF) computer, the compiler generates code that reads the unaligned data one byte at a time. |
22 |
| - |
23 |
| -## Remarks |
24 |
| - The `__unaligned` modifier is valid for the [!INCLUDE[vcprx64](../assembler/inline/includes/vcprx64_md.md)] and [!INCLUDE[vcpritanium](../cpp/includes/vcpritanium_md.md)] compilers but affects only applications that target an IPF computer. This modifier describes the alignment of the addressed data only; the pointer itself is assumed to be aligned. |
25 |
| - |
26 |
| - The [!INCLUDE[vcpritanium](../cpp/includes/vcpritanium_md.md)] processor generates an alignment fault when it accesses misaligned data, and the time to process the fault weakens performance. Use the `__unaligned` modifier to cause the processor to read data one byte at a time and avoid the fault. This modifier is not required for [!INCLUDE[vcprx64](../assembler/inline/includes/vcprx64_md.md)] applications because the [!INCLUDE[vcprx64](../assembler/inline/includes/vcprx64_md.md)] processor handles misaligned data without faulting. |
27 |
| - |
28 |
| - For more information about alignment, see: |
29 |
| - |
30 |
| -- [align](../cpp/align-cpp.md) |
31 |
| - |
32 |
| -- [__alignof Operator](../cpp/alignof-operator.md) |
33 |
| - |
34 |
| -- [pack](../preprocessor/pack.md) |
35 |
| - |
36 |
| -- [/Zp (Struct Member Alignment)](../build/reference/zp-struct-member-alignment.md) |
37 |
| - |
38 |
| -- [Examples of Structure Alignment](../build/examples-of-structure-alignment.md) |
39 |
| - |
40 |
| -## Example |
41 |
| - |
42 |
| -``` |
43 |
| -// unaligned_keyword.cpp |
44 |
| -// compile with: /c |
45 |
| -// processor: x64 IPF |
46 |
| -#include <stdio.h> |
47 |
| -int main() { |
48 |
| - char buf[100]; |
49 |
| - |
50 |
| - int __unaligned *p1 = (int*)(&buf[37]); |
51 |
| - int *p2 = (int *)p1; |
52 |
| - |
53 |
| - *p1 = 0; // ok |
54 |
| - |
55 |
| - __try { |
56 |
| - *p2 = 0; // throws an exception |
57 |
| - } |
58 |
| - __except(1) { |
59 |
| - puts("exception"); |
60 |
| - } |
61 |
| -} |
62 |
| -``` |
63 |
| - |
64 |
| -## See Also |
65 |
| - [Keywords](../cpp/keywords-cpp.md) |
| 17 | + |
| 18 | +**Microsoft specific**. When you declare a pointer with the `__unaligned` modifier, the compiler assumes that the pointer addresses data that is not aligned. Consequently, platform-appropriate code is generated to handle unaligned reads and writes through the pointer. |
| 19 | + |
| 20 | +## Remarks |
| 21 | + |
| 22 | +This modifier describes the alignment of the data addressed by the pointer; the pointer itself is assumed to be aligned. |
| 23 | + |
| 24 | +The necessity for the `__unaligned` keyword varies by platform and environment. Failure to mark data appropriately can result in issues ranging from performance penalties to hardware faults. The `__unaligned` modifier is not valid for the x86 platform. |
| 25 | + |
| 26 | +For more information about alignment, see: |
| 27 | + |
| 28 | +- [align](../cpp/align-cpp.md) |
| 29 | + |
| 30 | +- [__alignof Operator](../cpp/alignof-operator.md) |
| 31 | + |
| 32 | +- [pack](../preprocessor/pack.md) |
| 33 | + |
| 34 | +- [/Zp (Struct Member Alignment)](../build/reference/zp-struct-member-alignment.md) |
| 35 | + |
| 36 | +- [Examples of Structure Alignment](../build/examples-of-structure-alignment.md) |
| 37 | + |
| 38 | +## See also |
| 39 | + |
| 40 | +[Keywords](../cpp/keywords-cpp.md) |
0 commit comments