赛灵思微火焰结构填充/填料
Xilinx Microblaze Structure padding/Packing
我有两个结构:
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;
大小(大小 1) = 4;大小(大小 2) = 12;
我尝试获得的尺寸是 10 的 size2。
它在 num3 和 st_size 之间添加两个字节的填充。Microblaze Compiler 不支持 Pragma Pack
我正在尝试使用属性((打包)),但没有任何成功...
Struct _size2 {
short num; //2 bytes
short num2; //2 bytes
short num3; //2 bytes
size1 st_size; //4 bytes
}size2 __attribute__((packed));
我不确定出了什么问题,或者这是否以这种方式工作。
谢谢
您正在使用 unsigned int
位字段类型,即 gcc/Microblaze 上的 4 个字节。
implemantation 定义的unsigned short
位字段类型,使用 gcc/Microblaze 的大小为 2 个字节。
我在我的一个头文件中成功地使用它来描述以太网标头:
struct eth_hdr_st {
unsigned char dst_addr[6];
unsigned char src_addr[6];
unsigned short datatype;
} __attribute__ ((__packed__));
然后我像这样使用它:
struct eth_hdr_st eht_header;
注意,第一部分是名为eth_hdr_st
的结构的结构定义;第二部分是名为eth_header
的变量的声明,类型为struct eth_hdr_st
代码中的错误在于您将这些部分混合在一起,并尝试将__attribute__((packed))
应用于名为 size2
的变量。
相关文章:
- 在c++中用vector填充一个简单的动态数组
- 如何使用用户输入在C++中正确填充2D数组
- 如何找到大小'x'数组是否完全填充,在C++?
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 通过for循环使用用户输入填充列表
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 如何正确填充在堆上分配的二维数组?
- 将数字转换为填充字符串
- 有没有办法在一行中填充矢量图
- 用C++中的数字和条件填充向量
- 用真值填充矢量
- 使用结构成员指针在C++中填充结构
- 流填充字符的默认定位
- 使用不同算法的 PKCS1v15 填充进行加密 ++ 签名
- C++:使用缓冲区中的数据填充结构
- 如何将零填充的多维数组传递给 C++ 中的函数?
- Cryptopp:获取密码输入的填充字符串
- 填充上编译器生成的复制构造函数之间的不一致
- RcppEigen 模板化函数,用于填充单位法线
- 赛灵思微火焰结构填充/填料