type compatiblity in c and c++
I have heard from others that in c the type is struct compatible while it is name compatible in c++, but they have not given a detail description. Can anyone at here give me the insights of the type compatible and conversion?
thanks very much.
[250 byte] By [
tianqio] at [2007-11-20 11:37:28]

# 1 Re: type compatiblity in c and c++
Name type compatibility means two variables are compatible only if they are declared together, or with the same type. Example:
compatible
int a, b;
incompatible
int number;
string name;
Structure type compatibility means two variables are compatible if they have the same structure. This is harder to define, because you can have the same structure but different fields.
struct A
{
int a;
int b;
};
struct B
{
int Count;
int Index;
};
On the other hand, a and b below should be compatible:
typedef int Age;
Age a;
int b;
C uses structural compatibility for all types except structures and unions, where it uses declaration equivalence.
cilu at 2007-11-9 1:25:53 >

# 2 Re: type compatiblity in c and c++
I have searched for these compatiblity example in c and c++, I found a assertion says " in c , the basic types such as int and float are structure compatiblity and the user defined types like struct are name compatiblity, in c++,there only exists name compatiblity".
My understanding to this assertion is:
1.in c, you can assign a float to an int, if they are both occupy 4 bytes.
2.in c++.you can not do like this, if you assign an int to a float, the compiler will do type conversion implicitly,if you give an int a float value, compiler also does conversion but give you a warning.
Can I interpret it in this way?
thanks.