按位定義結構體
阿新 • • 發佈:2019-01-26
按位定義一個結構體
struct s_DosAttributes
{
unsigned ReadOnly :1;
unsigned Hidden :1;
unsigned System :1;
unsigned VolumeID :1;
unsigned Directory :1;
unsigned Archive :1;
unsigned reserved :2;
};
比如
struct s_DosAttributes st;
memset(&st, 0, sizeof(st));
st.ReadOnly = 1;
st.VolumeID = 1;
st.reserved = 3;
unsigned char c;
memcpy(&c, &st, sizeof(c));
這時c 的值是0xc9;