Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

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.

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
}
Show:
© 2015 Microsoft