简体   繁体   English

C编程语言中的位域

[英]Bitfields in C programming language

How to access entire structure members in C.Means I want to take all the data of variables in structure. 如何在C.Means中访问整个结构成员我想获取结构中变量的所有数据。

struct data
{
char a:1;
char b:2;
char c:3;
char d:1;
} arr;

I can access individual members by using . 我可以使用访问单个成员。 operator.But i need to access all members in that structure.Colud you please tell me how to do. 运算符。但是我需要访问该结构中的所有成员。请告诉我该怎么做。

As suggested make an union of the whole data and of the bitfield structure. 如建议的那样,对整个数据和位域结构进行合并。

union
{
    char Whole;
    struct data
    {
        char a:1;
        char b:2;
        char c:3;
        char d:1;
    } arr;
} MyData;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM