Why the sizeof(bool) is not defined to be one, by the Standard itself?

前端 未结 4 612
长情又很酷
长情又很酷 2020-11-30 10:52

Size of char, signed char and unsigned char is defined to be 1 byte, by the C++ Standard itself. I\'m wondering why it didn\'t define

4条回答
  •  天涯浪人
    2020-11-30 11:38

    Many platforms cannot effectively load values smaller than 32 bits. They have to load 32 bits, and use a shift-and-mask operation to extract 8 bits. You wouldn't want this for single bools, but it's OK for strings.

提交回复
热议问题