While reading some C++ code, I saw and was confused by this little line in a class:
bool x:1;
In debug builds, I noticed that 'x' is initialized as 'false', but I can not find any documentation about that. Can anyone tell me what this syntax does?
it's a bit field. read up on bit fields in your c++ textbook.
the initialization to false
is independent of the declaration. whether it is guaranteed by your code depends on your code (not given).
the c++ standard gives the compiler some leeway for integer and enumeration bitfields of size 1: storing the value 1
in such a field, you may get out the value -1
. happily this applies only to fields of size 1, and it does not apply to a field of type bool
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With