代碼1
const int size = 9;
char c[size];
1.VS2005 編譯為 C 代碼(/TC)
編譯不通過(guò)
錯(cuò)誤 1 error C2057: expected constant expression
錯(cuò)誤 2 error C2466: cannot allocate an array of constant size 0
錯(cuò)誤 3 error C2133: 'c' : unknown size
編譯通過(guò)
3.Cygwin gcc/g++
編譯通過(guò)
================================================
代碼2
int temp = 9;
const int size = temp;
char c[size];
1.VS2005 編譯為 C 代碼(/TC)
編譯不通過(guò)
錯(cuò)誤 1 error C2057: expected constant expression
錯(cuò)誤 2 error C2466: cannot allocate an array of constant size 0
錯(cuò)誤 3 error C2133: 'c' : unknown size
編譯不通過(guò)
錯(cuò)誤 1 error C2057: expected constant expression
錯(cuò)誤 2 error C2466: cannot allocate an array of constant size 0
錯(cuò)誤 3 error C2133: 'c' : unknown size
3.Cygwin gcc/g++
編譯通過(guò)
================================================
代碼3
int size;
scanf("%d", &size);
char c[size];
1.Cygwin gcc/g++
編譯通過(guò)
但不能對(duì)數(shù)組初始化。
2.VS2005
編譯不通過(guò)


