我读到 C89 不支持可变长度数组,但下面的实验似乎反驳了这一点:
#include <stdio.h>
int main()
{
int x;
printf("Enter a number: ");
scanf("%d", &x);
int a[x];
a[0] = 1;
// ...
return 0;
}
当我这样编译时(假设文件名为 va_test.c
):
gcc va_test.c -std=c89 -o va_test
有效...
我错过了什么? :-)
最佳答案
GCC 始终支持可变长度数组 AFAIK。将 -std 设置为 C89 不会关闭 GCC 扩展 ...
编辑:事实上,如果你在这里检查:
http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
在 -std= 下,您会发现以下内容:
ISO C90 programs (certain GNU extensions that conflict with ISO C90 are disabled). Same as -ansi for C code.
请注意“一定”这个词。
关于c - C89 中的可变长度数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4159746/