我一直在玩射线投射并决定使用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,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 1, 1, 1} }
};
答案 0 :(得分:2)
您定义大小为8x8x8
的数组,但使用9x8x8
元素初始化它。用以下方法修正大小:
#define MAP_01_WIDTH 9
或者更好的是,让编译器计算:
char MAP_01[][MAP_01_DEPTH][MAP_01_HEIGHT] = {...};