Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Warning (level 4) C4328
Collapse the table of content
Expand the table of content

Compiler Warning (level 4) C4328

Error Message

'function' : indirection alignment of formal parameter parameter_number (alignment_value_for_parameter) is greater than the actual argument alignment (actual_alignment)

By default on Itanium and CE (other than x86 CE based) platforms, data must be aligned to ensure that the application will run. This means that the address of a variable must be a multiple of the size of the variable's primitive type. (Two-byte Unicode strings must also be aligned.)

To resolve this warning, do not explicitly specify a struct alignment that will result in unaligned structure members. Or, explicitly specify that your function parameters will take unaligned data. For more information, see __unaligned and #pragma pack.

Example

C4328 can occur when you pass an unaligned pointer to a function expecting an aligned pointer.

The following sample generates C4328.

// C4328.cpp
// compile with: /W4 /Wp64
// processor: x64 IPF
#pragma pack(push)

#pragma pack(1)
struct S {
   int i;
};

struct Other {
   char c;
   S s;
};

// allow compiler to align structs on natural boundaries
#pragma pack(pop)

struct S2 {
   int i;
};

struct Other2 {
   char c;
   S2 s;
};

void f(int * p) {
   p++;
}

void f2(__unaligned int * p) {
   p++;
}

int main() {
   Other o;
   S* pS = &o.s;
   f(&pS->i);   // C4328
   f2(&pS->i);   // OK

   Other2 o2;
   S2* pS2 = &o2.s;
   f(&pS2->i);   // OK
}

The following sample is a more subtle cause of C4328. The following sample generates C4328.

// C4328_b.cpp
// compile with: /W4 /Wp64 /c
// processor: x64 IPF

// OK
struct T {
   int i;
};

void f2(int* p2);
void g2(T* t) {
   f2(&t->i);
}

// OK
#pragma pack(1)
struct U {
   int i;
};

void f3(__unaligned int* p3);
void g3(U* u) {
   f3(&u->i);
}

// warning
#pragma pack(1)
struct S {
   int i;
};

void f(int* p);
void g(S* s) {
   f(&s->i);   // C4328
   s->i = 0;
}

Community Additions

ADD
Show:
© 2015 Microsoft