#include <stdio.h>
struct test {
unsigned char first:4;
unsigned char next:4;
unsigned char second:4;
} __attribute__((packed));
void main(void)
{
struct test test;
test.first = 8;
test.next = 0;
test.second = 15;
unsigned char *ch = (unsigned char *)&test;
printf("M: %d L:%d; second%x\n", *ch >> 7, *ch & 0x0F, *(ch + 1));
}
输出如下:
M: 0 L:8; secondf
可以看出 是从bit 0开始使用的