【发布时间】:2018-05-07 19:53:56
【问题描述】:
我在编译时不断收到此错误。有人能告诉我为什么会这样吗? 我在 board.c 中声明了这些结构:
struct point {
short int rank;
short int file;
};
struct pieces {
Point pawns[8];
Point Knights[2];
Point BBishop;
Point WBishop;
Point Rooks[2];
Point Queen;
Point King;
};
board.h 中也有这些 typedef:
typedef struct point Point;
typedef struct pieces Pieces;
在主源文件 (chess.c) 中,我有声明:
Pieces White;
当我编译它说:
chess.c: In function 'main':
chess.c:19:10: error: storage size of 'White'isn't known
我尝试将结构移到board.h,效果很好。为什么当我在 board.c 中有结构时它不起作用?
gcc 编译器
【问题讨论】:
-
1 周前我刚刚完成了一个项目,其中涉及列表及其管理。我在 .c 源文件中声明了结构,它运行良好。
-
声明出现的顺序在 C 中很重要。将结构定义和 typedef 组合在 .h 文件中的同一位置通常是个好主意,这样它们将始终引用同一事物什么时候包含 .h 也没关系。
标签: c gcc struct compiler-errors