// define a new type called md5_t
typedef char md5_t[33];
md5_t g_md5;
// here sizeof(g_md5) == sizeof(md5_t)
void f(md5_t md5)
{
// here sizeof(md5) == sizeof(char*)
}
The type information definitely lost inside functions. // define a new type called md5_t
typedef char md5_t[33];
md5_t g_md5;
// here sizeof(g_md5) == sizeof(md5_t)
void f(md5_t md5)
{
// here sizeof(md5) == sizeof(char*)
}
The type information definitely lost inside functions. char test[1024][32];
printf("%i\n", sizeof(test));
You'll get 1024 * 32 (32,768). It didn't know that it's a 2D array. When you pass a stack-allocated array, it passes by pointer. It works this way because C is portable assembler.Secondly, it's not really meaningful to talk about "pass by pointer". Parameters are generally either passed by value, by reference, or by name. C only does pass by value; to emulate pass by reference, you need to pass the address by value, as a pointer - or as an "array". But the only array type you can declare is missing the crucial dimension length aspect.
Finally, saying that C works the way it does because it's portable assembler does not have strong explaining power. Arrays are not usually machine-level concepts; pointers with appropriate declaration syntaxes for static and automatic block allocations could take their place in C. Since C does have a higher-level construct called an array, it's not a big leap to imagine it being better designed.
#define ARRAY_SIZE(x) sizeof(x)/sizeof((x)[0])