: 在成员之后的结构声明中做什么

问题描述:

在:

struct foo {
  unsigned bar : 2;
};

':2' 有什么作用?

What does the ': 2' do?

它声明了一个 位域.该数字以位为单位指定该成员的大小.

It declares a bit field. The number specifies the size of that member in bits.