5

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?

Community
  • 1
  • 1
Jonathan M Davis
  • 37,181
  • 17
  • 72
  • 102

1 Answers1

9

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

Chaithra
  • 1,130
  • 3
  • 14
  • 22