This documentation is archived and is not being maintained.

Compiler Warning (level 4) C4121

'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.