3 ms·
Variable length arrays are a different feature. They are local temporary arrays of variable size: int f(size_t n) { int temp[n]; /* local array of
by Animats 12y ago
Variable length arrays are a different feature. They are local temporary arrays of variable size:
int f(size_t n) {
int temp[n]; /* local array of size n */
...
}
Someone once used that feature in the Linux kernel to get temp space for a string. It was taken out, because those arrays went on the stack and thus allowed large kernel stack growth based on data from outside the kernel.
Nobody uses that feature either.
- Peaker 12y agoEDIT: I now see what you mean, sorry for misunderstanding. The feature sounds useful, but the reason I misunderstood you is that you used the same syntax that represents array-to-ptr degradation, which made me think you were confused :-) I'm not sure how you would make this properly backwards compatible with C. You'd need to use a different syntax for such a major new feature. Kept here for posterity: You used variable length arrays in conjunction with ordinary array-of-array notation that (in function parameter list context) degrades to ptr-to-array. Here is the output of gcc on your code, with -Wvla (which warns about use of vla): gcc -c testvla.c -o /dev/null -Wvla -std=c99 testvla.c:3:1: warning: variable length array ‘a’ is used [-Wvla] void f(size_t m, size_t n, float a[m][n]) ^ testvla.c:3:1: warning: variable length array ‘a’ is used [-Wvla] The VLA is why your code is C99. If you use a[10][20] in the function prototype, it is ordinary C89, and if Microsoft wrote a C89 conformant compiler, it works on Microsoft's compiler as well.