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
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Warning (level 4) C4121

Error Message

'symbol' : alignment of a member was sensitive to packing

A structure member is aligned on a memory offset whose value is not a multiple of the member's size. For example, the following code snippet will produce this warning:

// C4121.cpp
// compile with: /W4 /c
#pragma pack(2) // C4121
struct s
{
   char a;
   int b;
};

You could make one of the following changes to prevent this warning:

  • Change pack(2) to pack(4).

  • Reverse the order of the structure members such that the int precedes the char.

When data is not aligned on boundaries that are multiples of the data's size performance can degrade and if you port your code to a RISC machine it will not compile.

You can specify the structure alignment with #pragma pack or /Zp. Note that the compiler does not generate this warning when /Zp1 is specified.

Community Additions

ADD
Show:
© 2015 Microsoft