代碼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
2.VS2005 編譯為 C++ 代碼(/TP)
編譯通過(guò)
3.Cygwin gcc/g++
編譯通過(guò)
================================================
代碼2int 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
2.VS2005 編譯為 C++ 代碼(/TP)
編譯不通過(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 size3.Cygwin gcc/g++
編譯通過(guò)
================================================
代碼3int size;
scanf("%d", &size);
char c[size];
1.Cygwin gcc/g++
編譯通過(guò)
但不能對(duì)數(shù)組初始化。
2.VS2005
編譯不通過(guò)
posted on 2010-08-22 16:25
custa 閱讀(2098)
評(píng)論(3) 編輯 收藏 引用