问题
GCC compiles the following function
void f(int i)
{
int a[i];
}
I was under the impression that you can only initialize arrays with constant length. Is this supposed to compile, and will it do what I expect it to?
回答1:
C99 added variable length arrays. And gcc
adds this to c89 as an extension with -std=gnu89
option (the default with gcc
).
In the latest C Standard, C11, variable length arrays support is marked as optional.
回答2:
VLA's are allowed in C99. GCC extention allows it to compile in C89 mode.
来源:https://stackoverflow.com/questions/19340544/gcc-allowing-arrays-to-be-initialized-with-variable-length