http://c0x.coding-guidelines.com/6.7.2.1.html:
如果 struct-declaration-list 不包含命名成员,其行为是未定义的。 这是否意味着以下内容是非法的?struct C { };
或者这是什么意思?
我在我的C库绑定中使用了一个指向空结构体(实际上是空的Ada记录)的Convention=>C
Ada指针来代替void*
(因为Ada中没有void*
)。我想知道这是否不正确。
我有什么误解?
请参见“不要将没有非零大小字段的结构体传递或返回给extern(C)函数。根据C11 6.7.2.1p8,这是未定义的行为。”,网址https://dlang.org/spec/struct.html。
struct C{ };
甚至无法匹配标准化语法。struct C {_Static_assert(1,"");};
可以(_Static_assert
是不必要的丑陋语法),但如果结构体内没有命名成员,则会产生未定义行为 (http://port70.net/~nsz/c/c11/n1570.html#6.7.2.1p8)。 - Petr Skocik