GCC告诉我如下:Transformations.h:16:1:error:initializer元素不是常量
这是代码:
const int X_ORIGIN = 1233086; const int Y_ORIGIN = -4728071; const int Z_ORIGIN = 4085704; const int xyzOrigin[NUM_DIMENSIONS] = {X_ORIGIN,Y_ORIGIN,Z_ORIGIN};
解决方法
您不能在C的全局范围内执行此操作,仅在本地范围内,即在函数中:
#define NUM_DIMENSIONS 3 const int X_ORIGIN = 1233086; const int Y_ORIGIN = -4728071; const int Z_ORIGIN = 4085704; const int xyzOrigin[NUM_DIMENSIONS] = {X_ORIGIN,Z_ORIGIN}; // FAIL void foo(void) { const int xyzOrigin[NUM_DIMENSIONS] = {X_ORIGIN,Z_ORIGIN}; // OK }
或者,您可以将代码编译为C而不是C.