Why is a char and a bool the same size in c++?

后端 未结 7 523
暗喜
暗喜 2020-11-29 05:05

I\'m reading The C++ Programming Language. In it Stroustrup states that sizeof(char) == 1 and 1 <= sizeof(bool). The specifics depend

7条回答
  •  我在风中等你
    2020-11-29 05:56

    Theoretically you only need a single bit for a bool, but working with less than 1 byte's worth of data is messy. You need more instructions to achieve anything and you don't really benefit.

    If you want to pack multiple booleans into a single byte you can use a bit-field structure.

提交回复
热议问题