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

后端 未结 7 513
暗喜
暗喜 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:51

    Actually, in most implementation that I know of sizeof(bool) == sizeof(int). "int" is intended to be the data size that is most efficient for the CPU to work with. Hence things which do not have a specific size (like "char") are the same size as an int. If you had a large number of them per object, you may want to implement a means of packing them for storage, but during normal calculation, it should be left it's native size.

提交回复
热议问题