I am a bit confused by the difference here on C99:
int myfunc (int array[n], int n) { ... }
will not compile. As far as I know, you should always refer to the size of the array first, so you need to write it:
int myfunc (int n, int array[n]) { ... }
But if you put the static keyword, this works absolutely fine:
int myfunc (int array[static 1], int n) { ... }
This order, if I am much preferable, since I'm used to the fact that the first arrays come in the function call, but why is this possible?
Edit: realizing that the third example is not actually a VLA, it helps ...
For reference, this was a piece of code that I was considering, and this led to the question:
int sum_array(int n, int m, int a[n][m]) { int i, j, sum = 0; for (i = 0; i < n; i++) for (j = 0; j < m; j++) sum += a[i][j]; return sum; }
source share