位域通常使用结构体声明, 该结构声明为每个位域成员设置名称,并决定其宽度:
struct bit_field_name
{
type member_name : width;
};
type:位域成员的类型,必须为 int、signed int 或者 unsigned int 类型。
C 语言使用 unsigned int 作为位域的基本单位,文章以下均默认 unsigned int 为 32 Bits,1个位域结构体占据32位。
位域通常使用结构体声明, 该结构声明为每个位域成员设置名称,并决定其宽度:
struct bit_field_name
{
type member_name : width;
};
type:位域成员的类型,必须为 int、signed int 或者 unsigned int 类型。
C 语言使用 unsigned int 作为位域的基本单位,文章以下均默认 unsigned int 为 32 Bits,1个位域结构体占据32位。