Why is sizeof(bool) not defined to be one by the C++ standard?

The other likely size for it is that of int, being the “efficient” integer type for the platform.

On architectures where it makes any difference whether the implementation chooses 1 or sizeof(int) there could be a trade-off between size (but if you’re happy to waste 7 bits per bool, why shouldn’t you be happy to waste 31? Use bitfields when size matters) vs. performance (but when is storing and loading bool values going to be a genuine performance issue? Use int explicitly when speed matters). So implementation flexibility wins – if for some reason 1 would be atrocious in terms of performance or code size, it can avoid it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)