Bit编程语言中的Bitfield [英] Bitfields in C programming language

查看:222
本文介绍了Bit编程语言中的Bitfield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问C.Means中的整个结构成员我想在结构中获取变量的所有数据。

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.

推荐答案

整个数据和位域结构的联合。

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;

这篇关于Bit编程语言中的Bitfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆