Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 2.4 KB

unaligned.md

File metadata and controls

64 lines (50 loc) · 2.4 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
__unaligned | Microsoft Docs
11/04/2016
cpp-language
language-reference
__unaligned_cpp
C++
__unaligned keyword [C++]
0cd83aad-1840-47e3-ad33-59bfcbe6375b
11
mikeblome
mblome
ghogen

__unaligned

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.

Remarks

The __unaligned modifier is valid for the [!INCLUDEvcprx64] and [!INCLUDEvcpritanium] 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.

The [!INCLUDEvcpritanium] 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 [!INCLUDEvcprx64] applications because the [!INCLUDEvcprx64] processor handles misaligned data without faulting.

For more information about alignment, see:

Example

// unaligned_keyword.cpp  
// compile with: /c  
// processor: x64 IPF  
#include <stdio.h>  
int main() {  
   char buf[100];  
  
   int __unaligned *p1 = (int*)(&buf[37]);  
   int *p2 = (int *)p1;  
  
   *p1 = 0;   // ok  
  
   __try {  
      *p2 = 0;  // throws an exception  
   }  
   __except(1) {  
      puts("exception");  
   }  
}  

See Also

Keywords