我尝试在
Linux和VS 2008中编译以下代码:
#include // this line has a ".h" string attached to the iostream string in the linux version of the code
using namespace std; // this line is commented in the linux version of the code
void main()
{
int a=100;
char arr[a];
arr[0]='a';
cout<
}
此行适用于g版本,但在Visual Studio中不起作用.
它会引发以下错误:
1>c:\users\bibin\documents\visual studio 2008\projects\add\add\hello.cpp(7) : error C2057: expected constant expression
1>c:\users\bibin\documents\visual studio 2008\projects\add\add\hello.cpp(7) : error C2466: cannot allocate an array of constant size 0
1>c:\users\bibin\documents\visual studio 2008\projects\add\add\hello.cpp(7) : error C2133: 'arr' : unknown size
这是一个有效的陈述吗?两个编译器如何对同一语言有不同的解释