#include<stdio.h>
struct s1
{
int a : 3;
int b : 32;
}s1;
struct s2
{
int a : 1;
int b : 3;
int c : 6;
}s2;
struct s3
{
char a : 3;
char b : 7;
}s3;
struct s4
{
char a : 1;
char b : 3;
}s4;
int main()
{
printf("%d\n", sizeof(s1));//8
printf("%d\n", sizeof(s2));//4
printf("%d\n", sizeof(s3));//2
printf("%d\n", sizeof(s4));//1
return 0;
}
位段存储是按照类型来确定最大bit位,通常有int char 两种。
int 的话如果第一个位段变量加上后面n个直到快超过4个字节,他们前面几个一共占四个字节
char类型找八个bit位段一组