带有位域的结构体的sizeof
C++: sizeof of struct with bit fields
为什么gcc返回13作为以下类的sizeof ?在我看来,我们应该得到e(4字节)+ d(4字节)+ 1字节(对于a和b) = 9字节。如果是对齐,那么大多数32位系统不是在8字节边界上对齐吗?
class A {
unsigned char a:1;
unsigned char b:4;
unsigned int d;
A* e;
} __attribute__((__packed__));
int main( int argc, char *argv[] )
{
cout << sizeof(A) << endl;
}
./a.o ut13
您很可能在64位平台上运行,指针的大小不是4而是8个字节。在a *上设置sizeof,然后打印出来
具有位域的结构体的实际大小取决于实现,因此gcc决定的大小将是正确的
相关文章:
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- 包含 std::list 的结构体的 C++ 初始化
- 结构体和类的不同大小(),彼此具有相同的字段类型
- 如何使用结构体的向量数组?
- 如何使用结构体在C++中更改这些代码?
- 无法在 Mosquitto MQTT Broker 插件上访问结构体 mosquitto 的元素
- 我应该如何在C++中使用结构体解决输入失败的问题?
- Qsort() 比较结构体整数的总和
- 如何使用迭代器指向结构体c++的向量
- 在C++中使用链表的堆栈实现中,访问结构体headNode成员count和top会导致运行时错误
- 如何获取结构体成员的地址
- 创建结构体向量,表达式:向量下标超出范围
- boost::任何带有结构体和无符号整数
- 如何在构造函数中初始化结构体的动态数组?
- 带有位域的结构体的sizeof
- 包含unordered_map成员的结构体的Sizeof()方法
- 内联结构体声明的Sizeof
- C/ c++混合源码:在C代码中获取sizeof(c++结构体)