This is one of the rough edges of the C language(s). Two declaration that look exactly the same (but for the names), one in the prototype and one as a stack variable, result in the declaration of two different types of variables.
void foo(int A[10]) {
int B[10];
}
Inside the scope of foo
, A
is pointer to int and B
is array of ten elements of type int
. As somebody else mentioned, even their sizes computed with sizeof
are different.
C++ inherited the rule, so for your example code the prototypes of both functions should be the same.
C99 complicates this matter even further by introducing the new keyword static
;-)
void foo(int A[static 10]) {
int B[10];
}
this doesn't change the rules on how A
and B
are seen from the inside, but provides an information to the caller side of howmuch array elements are expected. For the moment gcc accepts this new syntax and simply ignores this information.