size guarantee for integral/arithmetic types in C and C++

前端 未结 7 2160
难免孤独
难免孤独 2020-12-15 00:49

I know that the C++ standard explicitly guarantees the size of only char, signed char and unsigned char. Also it gives guarantees that

7条回答
  •  长情又很酷
    2020-12-15 00:55

    The C standard do not explicitly say that long has to be at least 4 bytes, but they do specify a minimum range for the different integral types, which implies a minimum size.

    For example, the minimum range of an unsigned long is 0 to 4,294,967,295. You need at least 32 bits to represent every single number in that range. So yes, the standard guarantee (indirectly) that a long is at least 32 bits.

    C++ inherits the data types from C, so you have to go look at the C standard. The C++ standard actually references to parts of the C standard in this case.

提交回复
热议问题