I'm trying to understand beatbits. The following example is presented in C ++ online docs .
#include <iostream>
struct S {
unsigned char b1 : 3, : 2, b2 : 6, b3 : 2;
};
int main()
{
std::cout << sizeof(S) << '\n';
}
What I do not understand in this example is that in the comments above the code says that after b1: 3 there are 2 unused bits. And then after b3: 2 there are 3 bits unused. Why? Shoudn 't which is the number of bits in unsigned char bits defined by type? Or the number of unauthorized bits remaining to the next boundary of the allocation unit?
source
share