利用共同体实现char和bool之间转换

//--------------------------------------------联合体(共用体) 定义
typedef union
{
    //使用位域
    struct
    {
        bool b0  : 1;
        bool b1  : 1;
        bool b2  : 1;
        bool b3  : 1;
        bool b4  : 1;
        bool b5  : 1;
        bool b6  : 1;
        bool b7  : 1;
    }bit_t;
    unsigned char byte;
}GetBit;//结构变量声明
 

 
//--------------------------------------------结构类型变量位域宏定义
#define flag_0    GetBit.bit_t.b0 
#define flag_1    GetBit.bit_t.b1
#define flag_2    GetBit.bit_t.b2
#define flag_3    GetBit.bit_t.b3
#define flag_4    GetBit.bit_t.b4
#define flag_5    GetBit.bit_t.b5
#define flag_6    GetBit.bit_t.b6
#define flag_7    GetBit.bit_t.b7

发布了38 篇原创文章 · 获赞 10 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/winux123/article/details/101034669