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 obviously 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?
Basically, the number after the colon describes how many bits that field uses.
Many languages including C and Java use the colon to indicate the text before it is a label, such as a target for a goto or an introduction to a case in a switch statement.
It defines i to be of 1 bit width. If i:x is given then it defines i to be x bits wide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With