In C language, if we have:
typedef int a[100];
typedef int b[200];
Then types a and b are equivalent? As far as I know C uses name equivalence, but I'm very confused.
In your example a is alias for the type int[100] and b is an alias for the type int[200]. These two types are not equivalent as an array's size is part of its type and different sizes mean different types.
If the second line were typedef int b[100];, a and b would be equivalent.
As far as i know C uses name equivalence
Structs and unions are nominally typed in the sense that if you have two struct (or union) types tagged A and B, which have exactly the same body, they're still considered different types. So if a variable has type struct A, you can't assign it a struct B without converting it first.
This is not true for typedefs, which are mere aliases. So if you have two typedefs typedef X a; typedef X b;, then X, a and b are all indistinguishable from each other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With