The :
operator is being used for bit fields, that is, integral values that use the specified number of bits of a larger space. These may get packed together into machine words to save space, but the actual behavior is implementation defined.
Now, the question "what should be the output of the sizeof operator" is straightforward but the answer is complicated.
The sizeof
operator says it returns the number of bytes, but the definition of "bytes" is not necessarily what you think it is. A byte must be at least 8 bits, but could be more than that. 9, 12, and 16 bits are not unheard of.
sizeof(int)
for a given platform can vary depending on the architecture word size. Assuming a byte size of 8 bits, sizeof(int)
might be 2, 4, or 8. Possibly more. With a byte size of 16, sizeof(int)
could actually be 1.
Now, remember I said that whether the bit fields get packed is implementation dependent? Well, that will make a big difference here. Each bit field could get put into a separate word. Or they all may be packed into one.
Most likely, you're on an Intel platform with 8-bit bytes and 32 or 64 bit int
s, and the compiler will probably pack the bit fields. Therefore your sizeof(bit1)
is likely to be 4 or 8.