C-位域

struct {
      unsigned char x1 : 2;
      unsigned char x2 : 2;
      unsigned char x3 : 2;
      unsigned char x4 : 2;
} Bunch;

/* sizeof(Bunch) => 1 */
struct {
      unsigned char x1: 2;
      unsigned char x2: 2;
      unsigned char : 0; /* 下一个位域在内存分配边界对齐 */
      unsigned char x4: 2;
} Bunch;
/* sizeof(Bunch) => 2 */

参考:http://www.qtbig.com/page/5/

posted @ 2020-09-05 00:42  朱小勇  阅读(131)  评论(0编辑  收藏  举报