以下代码可以在 gcc 4.5 中编译,但不能在 visual c 2005 中编译。
int main()
{
int len;
len = 32;
char buff[len];
return 0;
}
我知道我在语句之后声明数组,这违反了 ANSI C 规则。
但是为什么 GCC 没有给出任何错误或警告,而在 visual c 中,它给出了这样的错误,
error C2143: syntax error : missing ';' before 'type'
有什么想法吗?
谢谢。
最佳答案
您的 C 代码不符合 C90。 gcc -pedantic
将对此发出警告。
~/tmp$ gcc -pedantic a.c
a.c: In function ‘main’:
a.c:5: warning: ISO C90 forbids variable length array ‘buff’
a.c:5: warning: ISO C90 forbids mixed declarations and code
~/tmp$
关于c - 语句后的声明,gcc 4.5 vs visual c 2005,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6356059/