我一直在玩光线投射,并决定使用3D阵列来制作级别,但是TCC指出:
M_MAIN.C:19: error: index too large
数组的大小有限制吗?
代码:
#define MAP_01_WIDTH 8
#define MAP_01_HEIGHT 8
#define MAP_01_DEPTH 8
#define MAP_01_PLAYER_START_X 2
#define MAP_01_PLAYER_START_Y 2
#define MAP_01_PLAYER_START_Z 2
char MAP_01[MAP_01_WIDTH][MAP_01_DEPTH][MAP_01_HEIGHT] =
{
{ {1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 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1, 1} }
};
最佳答案
您使用8x8x8
元素定义数组,但使用9x8x8
元素初始化它。固定大小为:
#define MAP_01_WIDTH 9
或者更好的是,让编译器计算:
char MAP_01[][MAP_01_DEPTH][MAP_01_HEIGHT] = {...};
关于c - TCC错误:索引太大,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26076210/