Bitfields in C programming language

醉酒当歌 提交于 2019-12-12 06:27:30

问题


How to access entire structure members in C.Means I want to take all the data of variables in structure.

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.


回答1:


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;


来源:https://stackoverflow.com/questions/35934375/bitfields-in-c-programming-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!