程序在 C 中使用 std=c99,这是在 64 位机器上。
struct epochs {
volatile unsigned int epoch : 1;
volatile unsigned int pulse : 1;
volatile unsigned int active0 : 7;
volatile unsigned int active1 : 7;
volatile unsigned int counter0 : 24;
volatile unsigned int counter1 : 24;
};
当我检查 sizeof(epochs) 时,它给了我 12。
我可以告诉 gcc 不要通过添加 __attribute((packed)); 来填充它。所以我可以解决它。但是我真的很想知道为什么要添加 4 个字节来填充这个 64 位结构?
这里主要的是这个结构需要 64 位,因为它在 64 位原子交换操作中一次全部更新,这当然不适用于 12 字节值。