C随笔 8 : 联合体
作者:互联网
------------恢复内容开始------------
typedef struct
{
uint8 in:1;
uint8 to:1;
uint8 AppCheck:1;
uint8 AppCheckState:1;
uint8 AppChenckResult:1;
uint8 ref1:1;
uint8 reset:2;
uint8 app2bm;
uint8 fix;
uint8 crc;
} MagicNum_st;
typedef union
{
uint8 MagicNum[4];
MagicNum_st MagicNumBit;
}MagicNum_un;
看了老半天才发现这个魔术字是个联合体,对MagicNum的操作的等同于对应位置的MagicNum_st中某个成员的操作
联合体不太常用,记录注意下
MagicNum_un* const MagicNumber = (MagicNum_un*)0xFEF00000;
&MagicNumber->MagicNum == &MagicNumber->MagicNumBit == 0xFEF00000
------------恢复内容结束------------
标签:联合体,uint8,MagicNumber,------------,MagicNum,un,st,随笔 来源: https://www.cnblogs.com/yyyyloveu/p/15254441.html