怎么占一个字节

2019-08-06 16:37发布

union {
       struct {
          unsigned b0:1;
          unsigned b1:1;
          unsigned b2:1;
          unsigned b3:1;
          unsigned b4:1;
          unsigned b5:1;
          unsigned b6:1;
          unsigned b7:1;
          }oneBit;
         unsigned char allBits;
        } myFlag;
#define fast    myFlag.oneBit.b0
#define mid     myFlag.oneBit.b1
#define slow    myFlag.oneBit.b2
#define flow    myFlag.oneBit.b3
#define voice   myFlag.oneBit.b4
#define pause   myFlag.oneBit.b5
#define white   myFlag.oneBit.b6
#define on_off  myFlag.oneBit.b7
#define mark    myFlag.allBits
上面的语句在PICC中编译出来每一个占一个位,但在KEIL C中编译出来怎么占一个字节啊?如果在在KEIL C 中要实现如上功能,应该怎么写呢?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
13条回答
huangchui
2019-08-07 20:30
liliang9554 发表于 2014-2-14 23:42
这个不能怪Keil,是C标准规定了位域是2字节对齐的……也就是说就算你只定义了1bit的位域,它也要占用2字节 ...


真的假的,之前有一个通信协议的一个字节不同位段代表不同意思

一周热门 更多>