关于结构体中带:的赋值

 1 #include <stdio.h>
 2 #include <string.h>
 3  //using namespace std;
 4   typedef struct
 5  {
 6 
 7     unsigned int T_Alert       ;
 8     unsigned int Reserve1      : 3;
 9     unsigned int ResetDetected : 1;
10     unsigned int Reserve0      : 2;
11     unsigned int CmdStatus     : 1;
12     unsigned int CrcStatus     : 1;
13         
14 } regStatus;
15 
16 
17   int main(int argc , char *argv[])
18  {
19     regStatus aaa;
20     aaa.Reserve1=7;//在范围之内可以编译通过
21         aaa.Reserve1=8;//超出范围会报错
22     printf("%d\n",aaa.T_Alert);
23     printf("%d\n",aaa.Reserve1);
24     
25      return 0;
26  }    

 

分析,比如说结构体中的这个变量

unsigned int Reserve1      : 3; 
意思是说这个变量占这个数据类型的三位 把这个值赋值0-7都是对的,赋值超过7都是错的

转载于:https://www.cnblogs.com/tiantiantian-dianzi/p/5676368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值