C语言中位段实际运用

  • Post author:
  • Post category:其他


#include <QCoreApplication>
//#pragma anno_unions //如果出现报错,共用体可能不支持匿名结构嵌套
typedef union
{
    unsigned char BYTE;
    struct
    {
        unsigned char B0: 1;
        unsigned char B1: 1;
        unsigned char B2: 1;
        unsigned char B3: 1;
        unsigned char B4: 1;
        unsigned char B5: 1;
        unsigned char B6: 1;
        unsigned char B7: 1;
    };
}BIT_8;


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    BIT_8 bit8;
    bit8.B0=1;
    bit8.B7=1;
    printf("%#x",bit8.BYTE);
    return a.exec();
}



版权声明:本文为komtao520原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。