#include <stdio.h>
typedef struct weiyutest
{
unsigned a:3;
unsigned b:5;
unsigned c:8;
unsigned d:9;
}test;
int
main()
{
test weiyu;
int len = 0;
len = sizeof(weiyu);
printf("len is %d\n", len);
weiyu.a = 14;
weiyu.b = 15;
weiyu.c = 256;
weiyu.d = 512;
printf("a is %d b is %d c is %d d is %d\n", weiyu.a, weiyu.b, weiyu.c, weiyu.d);
return 0;
}
typedef struct weiyutest
{
unsigned a:3;
unsigned b:5;
unsigned c:8;
unsigned d:9;
}test;
int
main()
{
test weiyu;
int len = 0;
len = sizeof(weiyu);
printf("len is %d\n", len);
weiyu.a = 14;
weiyu.b = 15;
weiyu.c = 256;
weiyu.d = 512;
printf("a is %d b is %d c is %d d is %d\n", weiyu.a, weiyu.b, weiyu.c, weiyu.d);
return 0;
}
此处结果为:
len is 4
a is 6 b is 15 c is 0 d is 0
len为4是3+5+8+9=25 对齐为32bit 即4Bety 其它的由于数据溢出了 对的 我豆是故意的 具体的为什么是那样 若你懂的就懂 不懂的也就不懂了 &+&