2 回答
TA贡献1777条经验 获得超3个赞
假设字符串的前两个字符不是 '\000'
你有一个对齐问题,你的 C 编译器在 int16 后面多放了两个字节的填充,Go 不是
最简单的解决方法可能只是在“A”之后添加一个虚拟(填充)int16
type foo struct
{
A int16
A_pad int16
B int32
C [32]byte
}
或者这可能是一种告诉 go int32 需要“4 字节对齐”的方法
如果您知道一个,请编辑此答案或发表评论
TA贡献1871条经验 获得超13个赞
given:
0000000: 0700 0000 a91f 0000 7074 732f 3300 0000 ........pts/3...
the fields, per the struct, are:
0700h that will be the short int field, little endian format = 7
0000a91fh that will be the int field, little endian format = the big number
...
your struct needs a second short field to absorb the 0000h
then
0700h = 7
0000h = 0 in new field
a91f0000 = 8105
....
which indicates (amongst other things) that the struct is missing
the expected 2 byte padding between the short and the int fields
does the C code have #pragma pack?
- 2 回答
- 0 关注
- 252 浏览
添加回答
举报