I guess my question is whether the following is valid C
int main(void) {
int r = 3;
int k[r];
return 0;
}
If so, would some one care
It is a GCC extension that the current MSVC does not support. You can replace it in MSVC fairly easily with an _alloca (a stack allocation that requires no manual deallocation on the part of the programmer)
yes but it is limited to 1mb
The C99 standard added variable-length arrays, but other vendors such as GCC added them much earlier.
I'm sorry this is not an answer, but I'd like to point out a potential problem with using variable-length arrays. Most of the code that I have come across looks like this.
void foo(int n)
{
int bar[n];
.
.
}
There is no explicit error checking here. A large n
can easily cause problems.
It is a GCC extension that the current MSVC does not support. You can replace it in MSVC fairly easily with an _alloca (a stack allocation that requires no manual deallocation on the part of the programmer):
#include <malloc.h>
...
int *k = (int *)_alloca(sizeof(*k)*r);
It is in C99. MSVC only supports C89.