结构体中常见的冒号的用法是表示位域。
struct bs
{
int a:8;
int b:2;
int c:6;
};
struct bs
{
int a:8;
int b:2;
int c:6;
}data;
struct bs
{
unsigned a:4
unsigned :0
unsigned b:4
unsigned c:4
}
struct k
{
int a:1
int :2
int b:3
int c:2
};
void main(void)
{
struct bs
{
unsigned a:1;
unsigned b:3;
unsigned c:4;
} bit,*pbit;
bit.a=1;
bit.b=7;
bit.c=15;
printf("%d,%d,%d/n",bit.a,bit.b,bit.c);
pbit=&bit;
pbit->a=0;
pbit->b&=3;
pbit->c|=15;
printf("%d,%d,%d/n",pbit->a,pbit->b,pbit->c);
结构体中常见的冒号的用法是表示位域。
struct bs
{
int a:8;
int b:2;
int c:6;
};
struct bs
{
int a:8;
int b:2;
int c:6;
}data;
struct bs
{
unsigned a:4
unsigned :0
unsigned b:4
unsigned c:4
}
struct k
{
int a:1
int :2
int b:3
int c:2
};
void main(void)
{
struct bs
{
unsigned a:1;
unsigned b:3;
unsigned c:4;
} bit,*pbit;
bit.a=1;
bit.b=7;
bit.c=15;
printf("%d,%d,%d/n",bit.a,bit.b,bit.c);
pbit=&bit;
pbit->a=0;
pbit->b&=3;
pbit->c|=15;
printf("%d,%d,%d/n",pbit->a,pbit->b,pbit->c);