
2010年8月22日
代碼1
const int size = 9;
char c[size];
1.VS2005 編譯為 C 代碼(/TC)
編譯不通過
錯(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
2.VS2005 編譯為 C++ 代碼(/TP)
編譯通過
3.Cygwin gcc/g++
編譯通過
================================================
代碼2int temp = 9;
const int size = temp;
char c[size];
1.VS2005 編譯為 C 代碼(/TC)
編譯不通過
錯(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
2.VS2005 編譯為 C++ 代碼(/TP)
編譯不通過
錯(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 size3.Cygwin gcc/g++
編譯通過
================================================
代碼3int size;
scanf("%d", &size);
char c[size];
1.Cygwin gcc/g++
編譯通過
但不能對(duì)數(shù)組初始化。
2.VS2005
編譯不通過