空结构体的大小在不同编译器中,值是不同的。
GCC sizeof() return 0
G++ sizeof() return 1
GCC permits a C structure to have no members:
struct empty {
};
The structure will have size zero.
In C++, empty structures are part of the language. G++ treats empty structures as if they had a single member of type char.
本文探讨了空结构体在不同编译器中的表现,特别是在GCC和G++中的sizeof运算符返回值的区别。对于C语言,GCC允许结构体不包含成员且其大小为0;而在C++中,G++将空结构体视为含有一个char类型的成员。

1728

被折叠的 条评论
为什么被折叠?



