Compiler Warning (Level 1) C4742
Collapse the table of content
Expand the table of content
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. ArchiveDisclaimer

Compiler Warning (Level 1) C4742

Error Message

'var' has different alignment in 'file1' and 'file2': number and number

An external variable that was referenced or defined in two files has different alignment in those files. This warning is emitted when compiler finds that __alignof for the variable in file1 differs from __alignof for the variable in file2. This can be caused by using incompatible types when declaring variable in different files, or by using non-matching #pragma pack in different files.

To resolve this warning, either use the same type definition or use different names for the variables.

For more information, see pack and __alignof Operator.


This is the first file that defines the type.

// C4742a.c
// compile with: /c
struct X {
   char x, y, z, w;
} global;

The following sample generates C4742.

// C4742b.c
// compile with: C4742a.c /W1 /GL
// C4742 expected
extern struct X {
   int a;
} global;

int main() {
   global.a = 0;
© 2016 Microsoft