# 结构体中的冒号：位域

{ 位域列表 };

struct bs
{
int a:8;
int b:2;
int c:6;
};

struct bs
{
int a:8;
int b:2;
int c:6;
}data;

1. 一个位域必须存储在同一个字节中，不能跨两个字节。如一个字节所剩空间不够存放另一位域时，应从下一单元起存放该位域。也可以有意使某位域从下一单元开始。例如：

struct bs
{
unsigned a:4
unsigned :0 /*空域*/
unsigned b:4 /*从下一单元开始存放*/
unsigned c:4
}

2. 位域可以无位域名，这时它只用来作填充或调整位置。无名的位域是不能使用的。例如：

struct k
{
int a:1
int :2 /*该2位不能使用*/
int b:3
int c:2
};

32位机下，
short是2字节，共16bit，最大就不能超过16.
int是4字节，共32bit，最大就不能超过32.

fc_subtype占了4bit，fc_type占2bit,fc_protocol_version占2bit，共8bit，正好是一个字节。

### 4 replies ›

1. I have to point out my gratitude for your kind-heartedness giving support to those individuals that really need help with this particular concept. Your real commitment to getting the solution all over appeared to be remarkably effective and have in most cases made guys much like me to attain their aims. This warm and friendly information entails a lot to me and far more to my office colleagues. Regards; from each one of us.

2. I wish to point out my appreciation for your generosity giving support to individuals that have the need for guidance on the subject matter. Your special dedication to getting the message along became remarkably beneficial and have surely encouraged workers just like me to achieve their aims. Your entire informative tips and hints implies this much a person like me and additionally to my peers. Regards; from all of us.

3. Thank you so much for providing individuals with remarkably breathtaking possiblity to read critical reviews from this website. It is usually so lovely and full of a lot of fun for me and my office peers to search the blog on the least 3 times weekly to read the fresh secrets you have. And indeed, we’re usually astounded with all the striking concepts you give. Selected 2 tips on this page are in reality the very best I have ever had.

4. I as well as my friends came digesting the great techniques found on your web site and instantly came up with a terrible suspicion I never thanked the web site owner for them. All of the guys are already for this reason stimulated to learn all of them and now have pretty much been taking pleasure in these things. We appreciate you genuinely simply considerate and then for utilizing this form of perfect things most people are really eager to understand about. Our honest apologies for not expressing appreciation to sooner.