0

So I was working with bit fields, when I started thinking that when you create a bit field, for example

struct bit_field{
  unsigned int just_a_bit : 1;
  unsigned int five_bits  : 5;
  unsigned int            : 3; //Fill to 8 bits
}

You use unsigned int variable : bits;, what is this called (so I can search it)? Can this be used outside of creating bit fields, and would there be any point in doing so?

For clarity, by "this" I mean using colon with size in bits after the variable name whilst creating a variable.

YellowPeak
  • 20
  • 2

2 Answers2

4

That is simply called a "bit-field". It's only allowed within a struct (or a union, though it's of limited use in a union).

Community
  • 1
  • 1
nos
  • 223,662
  • 58
  • 417
  • 506
1

The members are bitfields.

The encapsulating class is still just a class.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055