0
class Test 
{

    struct
    {
      unsigned has_some_value1: 1;
      unsigned has_some_value2: 1;
    } info;
};

What does unsigned has_some_value1: 1; means?

Should be the following statement true: sizoef(type) == bit1 + ... + bitn ?

Vardan Hovhannisyan
  • 1,101
  • 3
  • 17
  • 40

2 Answers2

2

These are called "bit fields". has_some_value1 occupies one bit. has_some_value2 also occupies one bit—maybe the next physical bit in memory, or maybe not (depends how your compiler is configured to handle bit field alignment).

jez
  • 14,867
  • 5
  • 37
  • 64
  • sizeof() will obviously, at a very minimum, round up the size to the next whole number of *bytes* after adding up the bit widths and dividing by 8. But it may also be more, due to architecture- and compiler-specific struct alignment issues. – jez Nov 22 '13 at 14:39
1

A bitfield in a nonstatic instance of an un-named struct called "info", which is itself a member of "Test".

defube
  • 2,395
  • 1
  • 22
  • 34