Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 1015 Bytes

compiler-warning-level-4-c4366.md

File metadata and controls

38 lines (30 loc) · 1015 Bytes
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Warning (level 4) C4366
Compiler Warning (level 4) C4366
11/04/2016
C4366
C4366
65d2942f-3741-42f4-adf2-4920d5a055ca

Compiler Warning (level 4) C4366

The result of the unary 'operator' operator may be unaligned

If a structure member could ever be unaligned because of packing, the compiler will warn when that member's address is assigned to an aligned pointer. By default, all pointers are aligned.

To resolve C4366, either change the alignment of the structure or declare the pointer with the __unaligned keyword.

For more information, see __unaligned and pack.

Example

The following sample generates C4366.

// C4366.cpp
// compile with: /W4 /c
// processor: IPF x64
#pragma pack(1)
struct X {
   short s1;
   int s2;
};

int main() {
   X x;
   short * ps1 = &x.s1;   // OK
   int * ps2 = &x.s2;   // C4366
}