It seems like g++ ignores difference in array sizes when passing arrays as arguments. I.e., the following compiles with no warnings even with -Wall
.
void getarray(int a[500])
{
a[0] = 1;
}
int main()
{
int aaa[100];
getarray(aaa);
}
Now, I understand the underlying model of passing a pointer and obviously I could just define the function as getarray(int *a)
. I expected, however, that gcc will at least issue a warning when I specified the array sizes explicitly.
Is there any way around this limitation? (I guest boost::array is one solution but I have so much old code using c-style array which got promoted to C++...)