类型的大小与其无符号等价物的大小?

size of type vs its unsigned equivalent?

该标准规定了算术整数类型可以容纳的最小范围。但是,是否可以保证对于每个有符号整数,其无符号等价物具有相同的大小?

换句话说,是否总是这样:

sizeof(short) == sizeof(unsigned short)
sizeof(int) == sizeof(unsigned int)
sizeof(long) == sizeof(unsigned long)
sizeof(long long) == sizeof(unsigned long long)

?

(以下所有 ISO 标准参考均指 N4659: March 2017 post-Kona working draft/C++17 DIS


However, is there a guaranty that for each signed integer, its unsigned equivalent has the same size?

是的。

来自[basic.fundamental]/3[摘录,强调我的]:

[basic.fundamental]/3

For each of the standard signed integer types, there exists a corresponding (but different) standard unsigned integer type: “unsigned char”, “unsigned short int”, “unsigned int”, “unsigned long int”, and “unsigned long long int”, each of which occupies the same amount of storage and has the same alignment requirements as the corresponding signed integer type; [...]