有符号整数类型及其对应的无符号整数类型
Signed integer type and its corresponding unsigned integer type
对于每个有符号整数类型,标准保证存在对应的无符号整数类型。 6.2.5 p6
:
For each of the signed integer types, there is a corresponding (but
different) unsigned integer type (designated with the keyword unsigned
) that uses the same amount of storage (including sign information)
and has the same alignment requirements.
用关键字 unsigned
指定的短语 让我感到困惑,我查阅了标准的早期版本以了解它是否在那里出现。 C89/3.2.1.5 提供完全相同的措辞:
For each of the signed integer types, there is a corresponding (but
different) unsigned integer type (designated with the keyword
unsigned
) that uses the same amount of storage (including sign
information) and has the same alignment requirements.
现在考虑 uintptr_t
和 intptr_t
; uintmax_t
和 intmax_t
;等等...(这是可选的,但如果实现定义了这些类型)。
问题: 根据我上面引用的定义,uintptr_t
不是 intptr_t
和 uintmax_t
对应的无符号整数类型intmax_t
?
对应的无符号整数类型
我很担心,因为通常的算术转换使用术语 6.3.1.8 p1
:
Otherwise, both operands are converted to the unsigned integer type
corresponding to the type of the operand with signed integer type
所以我试图理解应用于 uintptr_t
和 intptr_t
的常用算术转换的语义。
标准“7.20.1.5 Greatest-width 整数类型”中的 header 和 header 下的描述,其中两种类型成对描述,假设 uintmax_t
被定义为对应于类型 intmax_t
.
的无符号类型
根据 7.20(4),这些是 typedef 名称,而不是基础类型。
For each type described herein that the implementation provides,261) <stdint.h>
shall declare that typedef name and define the associated macros.
7.20.1(1) 说:
When typedef names differing only in the absence or presence of the initial u are defined, they shall denote corresponding signed and unsigned types as described in 6.2.5;
所以我相信这些需要遵循与基本整数类型相同的默认转换规则。
直到 C99 才引入 intN_t
和 uintN_t
固定宽度类型,所以这可能就是您引用的标准缺少有关它们的信息的原因。
对于每个有符号整数类型,标准保证存在对应的无符号整数类型。 6.2.5 p6
:
For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword
unsigned
) that uses the same amount of storage (including sign information) and has the same alignment requirements.
用关键字 unsigned
指定的短语 让我感到困惑,我查阅了标准的早期版本以了解它是否在那里出现。 C89/3.2.1.5 提供完全相同的措辞:
For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword
unsigned
) that uses the same amount of storage (including sign information) and has the same alignment requirements.
现在考虑 uintptr_t
和 intptr_t
; uintmax_t
和 intmax_t
;等等...(这是可选的,但如果实现定义了这些类型)。
问题: 根据我上面引用的定义,uintptr_t
不是 intptr_t
和 uintmax_t
对应的无符号整数类型intmax_t
?
我很担心,因为通常的算术转换使用术语 6.3.1.8 p1
:
Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type
所以我试图理解应用于 uintptr_t
和 intptr_t
的常用算术转换的语义。
标准“7.20.1.5 Greatest-width 整数类型”中的 header 和 header 下的描述,其中两种类型成对描述,假设 uintmax_t
被定义为对应于类型 intmax_t
.
根据 7.20(4),这些是 typedef 名称,而不是基础类型。
For each type described herein that the implementation provides,261)
<stdint.h>
shall declare that typedef name and define the associated macros.
7.20.1(1) 说:
When typedef names differing only in the absence or presence of the initial u are defined, they shall denote corresponding signed and unsigned types as described in 6.2.5;
所以我相信这些需要遵循与基本整数类型相同的默认转换规则。
直到 C99 才引入 intN_t
和 uintN_t
固定宽度类型,所以这可能就是您引用的标准缺少有关它们的信息的原因。