我有两个结构:
Struct _size1 {
union{
short a;
struct {
char b;
char c;
}d;
struct {
char x;
char y;
}z;
};
union{
short a1;
struct {
char b1;
char c1;
}d1;
struct {
char x1;
char y1;
}z1;
};
}size1;
和:
Struct _size2 {
short num; //2 bytes
short num2; //2 bytes
short num3; //2 bytes
size1 st_size; //4 bytes
}size2;
sizeof(size1) = 4; sizeof(size2) = 12;
我试图获得的尺寸是 size2 的 10。
它在 num3 和 st_size 之间添加两个字节的填充。Microblaze 编译器不支持 Pragma Pack
我正在尝试使用属性((packed)) 但没有任何成功...
Struct _size2 {
short num; //2 bytes
short num2; //2 bytes
short num3; //2 bytes
size1 st_size; //4 bytes
}size2 __attribute__((packed));
我不确定出了什么问题,或者这是否有效。
谢谢