#include "stdlib.h"#include "stdio.h"struct { int a: 3; int b: 2; int c: 3; }s;int main(){ char *p = (char*)&s; *p = 0x99; printf("a: 0x%x, b: 0x%x, c: 0x%x\r\n", s.a, s.b, s.c);return 0;}
结构体位域中元素表示 类型+所占位数 ;
所以s结构体就占1个字节;而0x99刚好也是一个字节;
故而该字节中的位为 10011001 ;
在取值时按照INtel BIG-Endian 格式,所以s.a就取001,s.b就取11, s.c就取100;
最后按照符号位补齐为4bytes的整型。‘
故而最后答案为