struct bitdef {
unsigned int a:1;
unsigned int b:3;
unsigned int c:4;
};
#include <stdio.h>
struct bitdef {
unsigned int a:1;
unsigned int b:3;
unsigned int c:4;
};
int main(void)
{
struct bitdef test = {0};
struct bitdef *p = &test;
printf ("bitdef size: %d\n", sizeof(test));
return (0);
}
beyes@linux-kd1q:~/C/base/bitdef> ./bit
bitdef size: 4
struct bitdef {
unsigned int a:1;
unsigned int b:3;
unsigned int c:4;
unsigned int d:25;
};
#include <stdio.h>
struct bitdef {
unsigned int a:1;
unsigned int b:3;
unsigned int c:4;
};
int main(void)
{
struct bitdef test = {0};
struct bitdef *p = &test;
printf ("bitdef size: %d\n", sizeof(test));
test.a = 1;
printf ("0x%x\n", *((unsigned char *)p));
test.b = 7;
printf ("0x%x\n", *((unsigned char *)p));
test.c = 15;
printf ("0x%x\n", *((unsigned char *)p));
return (0);
}
beyes@linux-kd1q:~/C/base/bitdef> ./bit
bitdef size: 4
0x1
0xf
0xff
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |