在我的头文件中,我有这个:
typedef struct _client_value
{
int client_id;
struct timeval t;
size_t size;
char value[0];
} client_value;
我已经包含了<time.h>
,但是当我编译时,它显示:field 't' has incomplete type struct timeval t
。
我不明白为什么会出现这种情况。
在我的头文件中,我有这个:
typedef struct _client_value
{
int client_id;
struct timeval t;
size_t size;
char value[0];
} client_value;
我已经包含了<time.h>
,但是当我编译时,它显示:field 't' has incomplete type struct timeval t
。
我不明白为什么会出现这种情况。
sys/time.h
,而不是time.h
。 - zznchar value[0];
不符合 C 标准的编码,尽管它可能在某些编译器上“运行”。 - chux - Reinstate Monicachar value[0];
是“结构体技巧”的一种变化形式,这种技巧已经被 C99 中添加的“灵活数组成员”所取代,写作char value[];
— 数组中根本没有维度。经典的“结构体技巧”使用char value[1];
— GCC 和模拟它的编译器支持char value[0];
,但是 C 标准不支持(标准从未正式支持过结构体技巧 — 但它总是能工作,因为编译器作者是现实主义者)。 - Jonathan Leffler