I stumbled into a weirdness today with the C language that I cannot understand the reasoning behind.
If i have a function like this (assume 32 bit architecture):
void printSize(char array[6]) {
printf("%zd\n", sizeof array);
}
I will get back 4, which is the size of the pointer. I was expecting to get 6, which is the explicitly declared size in the function prototype.
I get that arrays are passed by reference, and that the underlying type is a pointer. I was assuming that putting the length of the array in the prototype would provide the compiler with the information it needed to return 6.
why does C do this? Also, what is the point of putting a size in a prototype if the compiler can't even do sizeof(), returning that size?
void printSize(char (*array)[6]);versusvoid printSize(char (*array)[]);?