4

Possible Duplicate:
What does the : do in a struct declaration after a member

I would like to ask why the : character was added in this struct:

typedef union A
{
struct 
    {
        ubyte B:4;
         }
} struct_a;

Thanks in advance;

Community
  • 1
  • 1
Rida Shamasneh
  • 767
  • 1
  • 6
  • 16

3 Answers3

4

The :4 is putting a 4-bit limit on the variable. See Section 6.9 of Kernighan & Ritchie.

borrible
  • 17,120
  • 7
  • 53
  • 75
3

It's called a bit field. In this case it is saying the B is 4 bits in size.

Andrew White
  • 52,720
  • 19
  • 113
  • 137
2

It declares a bit field with 4 bits.

user786653
  • 29,780
  • 4
  • 43
  • 53