typedef struct AA{
short a:3;
short b:3;
short c:3;
}AA;
typedef union BB{
AA aa;
char dat;
}BB;
int main(int argc, char* argv[]){
BB bb;
bb.dat = (char)151; //010 010 111
//注意大小端问题:win7小端
printf("%d\n", bb.aa.a);//111 扩展符号位:1111 1111 1111 1111 == -1
printf("%d\n", bb.aa.b);//010 2
printf("%d\n", bb.aa.c);//010 2
printf("%d\n", sizeof(BB)); //BB的大小,即为AA的大小:2
return 0;
}
short a:3;
short b:3;
short c:3;
}AA;
typedef union BB{
AA aa;
char dat;
}BB;
int main(int argc, char* argv[]){
BB bb;
bb.dat = (char)151; //010 010 111
//注意大小端问题:win7小端
printf("%d\n", bb.aa.a);//111 扩展符号位:1111 1111 1111 1111 == -1
printf("%d\n", bb.aa.b);//010 2
printf("%d\n", bb.aa.c);//010 2
printf("%d\n", sizeof(BB)); //BB的大小,即为AA的大小:2
return 0;
}