在C ++中有没有一个合法的方式来定义零大小的类型? < eom> [英] Is there a legal way to define type with zero-size in C++? <eom>
问题描述
可能重复:
can sizeof return 0(zero)
在C ++中用零大小来定义类型的法律方式?
C ++标准。 > 1.8.5。 9.6.2。
除非是位字段(9.6),否则最导出的对象应具有非零大小,应占用一个或多个
字节的存储空间。基类子对象可以具有零大小。 POD类型(3.9)的对象将占据
个连续字节的存储空间。
对省略标识符的位字段的声明声明未命名的位字段。未命名的位字段是
不是成员,不能被初始化。作为特殊情况,具有零宽度的未命名位字段指定在分配单元边界处的下一位字段的对齐
。只有当声明一个未命名位字段可能
时,constant-expression是一个等于零的值。
Possible Duplicate:
Can sizeof return 0 (zero)
Is there a legal way to define type with zero-size in C++?
C++ Standard.
1.8.5. Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more bytes of storage. Base class sub-objects may have zero size. An object of POD type (3.9) shall occupy contiguous bytes of storage.
9.6.2. A declaration for a bit-field that omits the identifier declares an unnamed bit-field. Unnamed bit-fields are not members and cannot be initialized. As a special case, an unnamed bit-field with a width of zero specifies alignment of the next bit-field at an allocation unit boundary. Only when declaring an unnamed bit-field may the constant-expression be a value equal to zero.
这篇关于在C ++中有没有一个合法的方式来定义零大小的类型? < eom>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!