What does the colon do in this structure definition?

Possible duplicate:
What does unsigned temp: 3 mean?

I do not understand this definition of structure. It seems illegal to me, but apparently it is not:

typedef struct { unsigned i:1; } my_struct; 

I believe that the designation of an unsigned variable without a type is the same as the designation of an unsigned int . However, I am completely puzzled by the colon. What does it do? I guess this is a kind of initializer, but I don't know what that means. From the top of my head, the only place I expect the colon in C is in the ternary operator, which obviously isn't. So this seems to be a construction that I am not familiar with. Can anyone explain what the purpose of the colon is in defining this structure? What does the declaration unsigned i:1; mean unsigned i:1; ?

+4
source share
1 answer

It determines that I have a width of 1 bit. If i: x is given, then it determines that I have a width of x bits.

+8
source

All Articles