Colon initialization bool

When reading some C ++ code, I saw and was confused by this little line in the class:

bool x:1; 

In debug builds, I noticed that "x" is initialized to "false", but I can not find documentation about this. Can someone tell me what this syntax does?

+4
source share
1 answer

This is a bit field. read in the bit fields in the C ++ tutorial.

initialization to false is independent of the declaration. regardless of whether your code is guaranteed, depends on your code (not specified).

the C ++ standard gives the compiler some leeway for integer and enumerable bit fields of size 1: storing the value 1 in such a field, you can get a value of -1 . fortunately, this applies only to fields of size 1 and does not apply to a field of type bool .

+9
source

All Articles