小编Dan*_*Dan的帖子

为什么此联合中的结构似乎向后排序

#include <stdio.h>

union bits_32{
    unsigned int x;
    struct {char b4,b3,b2,b1;} byte;
} ;

int main(int argc, char **argv){
    union bits_32 foo;
    foo.x=0x100000FA;
    printf("%x",foo.byte.b4 & 0xFF);
}
Run Code Online (Sandbox Code Playgroud)

这将输出FA.为什么不输出10因为b4占据了第一个空间?

c struct bit-manipulation unions

2
推荐指数
1
解决办法
231
查看次数

标签 统计

bit-manipulation ×1

c ×1

struct ×1

unions ×1