当前位置:网站首页>C语言位域应用--一个字节存八个标志位
C语言位域应用--一个字节存八个标志位
2022-04-22 19:55:00 【RYYB】
/* define.h */
typedef struct {
unsigned char bit0 :1;
unsigned char bit1 :1;
unsigned char bit2 :1;
unsigned char bit3 :1;
unsigned char bit4 :1;
unsigned char bit5 :1;
unsigned char bit6 :1;
unsigned char bit7 :1;
}_STC_BIT;
#define DEF_BIT7(pdata) ((volatile _STC_BIT*)(pdata))->bit7
#define DEF_BIT6(pdata) ((volatile _STC_BIT*)(pdata))->bit6
#define DEF_BIT5(pdata) ((volatile _STC_BIT*)(pdata))->bit5
#define DEF_BIT4(pdata) ((volatile _STC_BIT*)(pdata))->bit4
#define DEF_BIT3(pdata) ((volatile _STC_BIT*)(pdata))->bit3
#define DEF_BIT2(pdata) ((volatile _STC_BIT*)(pdata))->bit2
#define DEF_BIT1(pdata) ((volatile _STC_BIT*)(pdata))->bit1
#define DEF_BIT0(pdata) ((volatile _STC_BIT*)(pdata))->bit0
/* xxx.h */
extern unsigned char status;
...
#define flag_xx4 DEF_BIT4(&status)
#define flag_xx3 DEF_BIT3(&status)
#define flag_xx2 DEF_BIT2(&status)
#define flag_xx1 DEF_BIT1(&status)
#define flag_xx0 DEF_BIT0(&status)
以上来自瑞萨demo。
或者:
union {
struct {
uint8_t flag_xx0 : 1;
uint8_t flag_xx1 : 1;
uint8_t flag_xx2 : 1;
uint8_t flag_xx3 : 1;
uint8_t rsv : 4;
}flag;
uint8_t flags;
}
版权声明
本文为[RYYB]所创,转载请带上原文链接,感谢
https://blog.csdn.net/ponyma_/article/details/123996243
边栏推荐
- go实现 银行卡Luhn校验
- More than 100 days, 0 basic self-study and career change software testing, from 3000 to 15K monthly salary, I compiled a super complete learning guide
- 嵌入式Web项目(一)——Web服务器的引入
- 《PyTorch深度学习实践》09 多分类问题
- Linux下安装Mysql 8.0 + eclipse配置详细教程
- See how big websites play the secret of website acceleration (CDN)
- x16为什么比x8慢?
- 怎么才能申购可转债呢?申购可转债安全吗?
- 2-way can / can FD data recording diagnostic instrument solves the difficulty of accidental errors for enterprises
- EasyCVR流媒体内核无法启动是什么原因?
猜你喜欢

Advanced IPC - DBUS details
![[2022 fresh students see] can an inexperienced college graduate change his career to do software testing?](/img/62/3726b18cd949c30a717845b519d22c.png)
[2022 fresh students see] can an inexperienced college graduate change his career to do software testing?

为什么我建议你从事技术岗,而非文职,销售

时序数据库市场漫谈

树的那些破事~模板小结

EasyCVR流媒体内核无法启动是什么原因?

开源免费,最好用的3大系统9大防火墙软件安利给你们

Quarkus dependency injection 9: bean read / write lock

2022年Postman最被低估的功能,自动化接口测试效率简直无敌
![[Niuke brush question 19] MP3 cursor position](/img/ea/8ec110cbacf68ea0337437e311cc72.png)
[Niuke brush question 19] MP3 cursor position
随机推荐
2021应届毕业生该何去何从?
Is it better to do operation or software testing?
百度被美国列入确定摘牌清单,ICLR 2022杰出论文公布,清华量子计算创业公司浮出水面 ,今日更多大新闻在此
Implementation of calico official website network topology: Based on ENSP and vmvare
Is it true to download the financial app of qiniu business school? Is it safe to open an account in qiniu
Where should 2021 fresh graduates go?
期货开户在手机上办理安全吗?需要线下客户经理协助办理吗?
[recent function update] seamless experience free demo!
[2022 fresh students see] can an inexperienced college graduate change his career to do software testing?
go语言的时间格式
【2022应届生看过来】一个无经验的大学毕业生,可以转行做软件测试吗?
一百多天,0基础自学转行软件测试,从月薪3000到15k,我整理的超全学习指南
2021-06-10 axure本地发布
When MySQL designs a table, two timestamp fields are required
FPGA SEU problem and SEM core
Household intelligent projector is the first choice, entering the polar meter h3s projection
Which futures company is safer to open a domestic futures account?
[渝粤教育] 四川农业大学 管理学原理 参考 资料
[Niuke brush question 19] MP3 cursor position
Golang本地缓存选型对比及原理总结