Skip to content

Commit d07907b

Browse files
authored
Address C4743 weirdness per 3955 (MicrosoftDocs#4359)
1 parent 7f999d6 commit d07907b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎docs/error-messages/compiler-warnings/compiler-warning-level-1-c4743.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
---
22
description: "Learn more about: Compiler Warning (Level 1) C4743"
33
title: "Compiler Warning (Level 1) C4743"
4-
ms.date: "05/13/2019"
4+
ms.date: 06/16/2022
55
f1_keywords: ["C4743"]
66
helpviewer_keywords: ["C4743"]
77
ms.assetid: 2ee76ea3-77f3-4c2f-9a57-0751823c89fd
88
---
99
# Compiler Warning (Level 1) C4743
1010

11-
'*type*' has different size in '*file1*' and '*file2*': *number* and *number* bytes
11+
> '*type*' has different size in '*file1*' and '*file2*': *size_1* and *size_2* bytes
1212
1313
An external variable referenced or defined in two files has different types in those files, and the compiler determined that the size of the variable in *file1* differs from the size of the variable in *file2*.
1414

1515
## Remarks
1616

17-
There is an important case when this warning can be emitted for C++. If you declare the same types with the same name in two different files, if those declarations contain virtual functions, and if the declarations are not the same, then the compiler can emit warning C4744 for the virtual function tables. The warning occurs because there are two different-sized virtual function tables for the same type, and linker must choose one of them to incorporate into the executable. It is possible that it can result in your program calling the wrong virtual function.
17+
There's an important case when this warning can be emitted for C++. If you declare class types with the same name in two different files, if those declarations contain virtual functions, and if the declarations aren't the same, then the compiler can emit warning C4744 for the virtual function tables. The warning occurs because there are two different-sized virtual function tables for the same type, and the linker must choose one of them to incorporate into the executable. It's possible that it can result in your program calling the wrong virtual function.
1818

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

2121
## Example
2222

23-
The following sample generates C4743. To compile it, place both files in the same folder, then run
23+
The following sample generates C4743. To compile it, place both files in the same folder, then run this command in a developer command prompt:
2424

2525
```cmd
2626
cl /EHsc /W1 /GL /O2 C4743a.cpp C4743b.cpp
2727
```
2828

29+
Source file *`C4743a.cpp`*:
30+
2931
```cpp
3032
// C4743a.cpp
3133
class C {
@@ -41,6 +43,8 @@ void C::f3(void) {}
4143
C q;
4244
```
4345
46+
Source file *`C4743b.cpp`*:
47+
4448
```cpp
4549
// C4743b.cpp
4650
class C {
@@ -58,3 +62,5 @@ C x;
5862
5963
int main() {}
6064
```
65+
66+
To resolve this issue, rename one of the `C` classes.

0 commit comments

Comments
 (0)