问题描述
如果在我的体系结构中一个单词是4个字节,我希望填充以下结构,以便至少一个单词(4个字节)。
// 4 bytes
struct
{
uint8_t High : 4;
uint8_t Low : 4;
} Value;
现在,假设我具有以下嵌套结构:
// ? bytes
struct
{
uint8_t Address;
struct
{
uint8_t High : 4;
uint8_t Low : 4;
} Value;
} Register;
如何包装此结构? Value
会保留一个字(4个字节)的大小吗?我期望有两种方式可以打包这种结构,但是我不知道哪种是正确的,甚至是哪一种都不正确。假设R
的{{1}}沙子,Register
是成员A
,而Address
是成员V
。我能想到的两种方法是:
第一:
Value
第二:
Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
R = A 0 0 0 V 0 0 0
谢谢!
解决方法
此结构按以下方式打包:
Byte1 Byte2 Byte3 Byte4
R = A V 0 0