在 C 中使用零长度数组有什么优点?
例如:
struct email {
time_t send_date;
int flags;
int length;
char body[];
}list[0];
最佳答案
大小为 0
的数组在 C 中无效。
char bla[0]; // invalid C code
来自标准:
(C99, 6.7.5.2p1) "If the expression is a constant expression, it shall have a value greater than zero."
因此 list
声明在您的程序中无效。
以不完整类型作为结构体最后一个成员的数组是灵活数组成员。
struct email {
time_t send_date;
int flags;
int length;
char body[];
};
这里body
是一个灵活的数组成员。
关于c - 零长度数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12412067/