开发者

What does the colon do in this struct definition? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

What does 'unsigned temp:3' means

I don't understand this struct definition. It seems illegal to me, but apparently it isn't:

typedef struct
{
    unsigned i:1;
} my_struct;

I believe that marking the variable as unsigned without a type is the same as marking it as unsigned int. However, I'm completely baffled by the colon. What does it do? My guess is that it's some sort of initializer, but I haven't a clue what it means. Off the top of my head, the only place that I'd expect a colon in C is in the ternary operator, which this obvi开发者_运维技巧ously isn't. So, this appears to be a construct with which I am not familiar. Can anyone explain what the purpose of the colon is in this struct definition? What exactly does the declaration unsigned i:1; mean?


It defines i to be of 1 bit width. If i:x is given then it defines i to be x bits wide.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜