【发布时间】:2016-08-24 19:43:49
【问题描述】:
我有一个看起来像这样的结构:
typedef struct foo {
int this;
int that;
int length;
int info[]; // legal for last element of a struct
} Foo;
当我编译它时,我收到这样的警告:
C4200 nonstandard extension used: zero-sized array in struct/union
我只是忍受警告,还是我可以设置一些属性来告诉 Visual Studio 使用 C-99?
【问题讨论】:
-
不要“忍受”警告。
struct的大小未知。如果不知道数组的大小,将该成员定义为指针,并根据需要分配内存。 -
不,MSVC 不支持 0 长度数组。如果您希望
struct溢出到分配的内存(从它的最后一个成员),请将成员字符串定义为[1]并让它溢出到正确分配的内存中。 -
msdn.microsoft.com/en-us/library/79wf64bc.aspx -- 关键文本是“声明零大小数组是 Microsoft 扩展”
-
MSVC 不符合 C99。 (适用于一些)
-
实际上,在
struct中,成员char z[]已被MSVC 接受为零长度成员,因此请接受我的道歉。
标签: c visual-studio-2015 c99