在 C99 标准中哪里说有符号整数溢出是未定义的行为?
Where in the C99 standard does it say that signed integer overflow is undefined behavior?
C99 标准中的什么地方说有符号整数溢出是未定义的行为?
我在第 6.2.5 节中看到关于无符号整数溢出定义明确的评论(参见 Why is unsigned integer overflow defined behavior but signed integer overflow isn't?):
A computation involving unsigned operands can never overflow,
because a result that cannot be represented by the resulting unsigned integer type is
reduced modulo the number that is one greater than the largest value that can be
represented by the resulting type.
但我正在查看关于未定义行为的附录 J,我只在列表中看到这些类似的项目:
An expression having signed promoted type is left-shifted and either the value of the
expression is negative or the result of shifting would be not be representable in the
promoted type
和
The value of the result of an integer arithmetic or conversion function cannot be
represented
(注意这里指的是 "an integer arithmetic function",不是整数运算本身
我没有 C99 的副本,但在 C11 标准中,这段文字出现在第 6.5 节第 5 段中:
If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined.
这似乎是所有溢出的包罗万象;关于无符号整数的文本然后成为 6.5 以上的特例 ¶ 5.
C99 标准中的什么地方说有符号整数溢出是未定义的行为?
我在第 6.2.5 节中看到关于无符号整数溢出定义明确的评论(参见 Why is unsigned integer overflow defined behavior but signed integer overflow isn't?):
A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
但我正在查看关于未定义行为的附录 J,我只在列表中看到这些类似的项目:
An expression having signed promoted type is left-shifted and either the value of the expression is negative or the result of shifting would be not be representable in the promoted type
和
The value of the result of an integer arithmetic or conversion function cannot be represented
(注意这里指的是 "an integer arithmetic function",不是整数运算本身
我没有 C99 的副本,但在 C11 标准中,这段文字出现在第 6.5 节第 5 段中:
If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined.
这似乎是所有溢出的包罗万象;关于无符号整数的文本然后成为 6.5 以上的特例 ¶ 5.