Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.3 KB

compiler-warning-level-1-c4742.md

File metadata and controls

48 lines (36 loc) · 1.3 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Warning (Level 1) C4742
Compiler Warning (Level 1) C4742
07/22/2020
C4742
C4742
e520881d-1eeb-48b1-9df0-8017ee8ba076

Compiler Warning (Level 1) C4742

'variable' has different alignment in 'file1' and 'file2': number1 and number2

An external variable that was referenced or defined in two files has different alignment in those files.

Remarks

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.

Example

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;
}