C使用常量声明一个2d数组

Spe*_*cer 1 c arrays constants

我有一个游戏的头文件,声明一个2d数组的板.

#ifndef GAME_H_
#define GAME_H_

static const int columns = 15;
static const int rows = 15;

int board[rows][columns];

#endif /* GAME_H_ */
Run Code Online (Sandbox Code Playgroud)

我收到错误" error: variably modified 'board' at file scope".

Ste*_*e M 7

C不允许const变量作为数组边界.改为使用枚举:

enum { columns = 15, rows = 15 };
Run Code Online (Sandbox Code Playgroud)