Dear all
Hi
I encountered a simple but IMO important problem about the C++ linkage
model and One Definition Rule. Why the following code link?
file1.cpp
int x;
file2.cpp
double x;
x was defined in two different translation units with different types.
It breaks the ODR.
The following code is also linked:
file1.cpp
int x;
file2.cpp
extern double x;
It is obvious the type x in declaration and definition are different.
I ran and tested codes in Visual Studio 6.0 and .Net 2005.
Thank you in advance
- Saeed Amrollahi
Hi
I encountered a simple but IMO important problem about the C++ linkage
model and One Definition Rule. Why the following code link?
file1.cpp
int x;
file2.cpp
double x;
x was defined in two different translation units with different types.
It breaks the ODR.
The following code is also linked:
file1.cpp
int x;
file2.cpp
extern double x;
It is obvious the type x in declaration and definition are different.
I ran and tested codes in Visual Studio 6.0 and .Net 2005.
Thank you in advance
- Saeed Amrollahi
Comment