I am having hard time understanding typedef pattern for arrays.
typedef char Char10[10];
void fun (Char10 a) // not passing reference (interested in pass by value)
{
if(typeid(Char10) == typeid(char*))
throw 0; // <--- never happens
}
int main ()
{
char a[10]; fun(a); // ok
char b[11]; fun(b); // why works ?
}
Why the different sizes of array by value are accepted by fun() ? Are char[10] and char[11] not different types ?
Edit: For those who says it decays to pointer, see my edited code. char[10] and char* doesn’t seem to match.
They are different types, you’re right.
It’s a misleading quirk of C++ that you can be seen to have a function
Since you cannot pass arrays by value, and C++ is silly, this is actually the function
And, of course, both inputs degrade happily to
char*.It would be nice if C++ did not let you even pretend to accept an array by value, but it is silly in this way.. inherited from C.