The naming convention used in `<cstdint>`

The header <cstdint>( <stdint.h>) defines several integral types, and their names follow this pattern:, intN_twhere Nis the number of bits, not bytes.

Given that the byte is not strictly defined as 8 bits long, why are these types not defined, for example, int1_tinstead int8_t? Wouldn't that be more appropriate since it allows for machines with bytes of unusual lengths?

+5
source share
3 answers

On machines that do not have exactly these sizes, types are not defined. That is, if the machine does not have an 8-bit byte, then it int8_twill be unavailable. However, you would still have the smallest versions, for example int_least16_t.

, , , , , , . , - 8- , 8 , , .


.

+6

int32_t 4- 8- , 2- 16- , 1- 32-, - . , .

+5

The idea of ​​using these types is to explicitly specify the number of bits that you can store in a variable. As you pointed out, different architectures may have different byte sizes, so the number of bytes does not guarantee the number of bits that your variable can handle.

+3
source

All Articles