c - C99 标准中的哪里说有符号整数溢出是未定义的行为?

标签 c c99 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



我没有 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 以上的特例。

关于c - C99 标准中的哪里说有符号整数溢出是未定义的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342460/


c - 信息 C5012 : loop not parallelized due to reason '1008'

c++ - 当 extern 声明和定义之间存在不匹配的类型时会出现什么行为?

Javascript 无法在另一个函数内调用数组推送

Java list.contains 返回 false,应该是 true

c - fork() 输出

c - 出现 Apple Mach-O 链接器错误 C99。我如何解决它?


(u/i)int_fastN_t 需要澄清

c++ - Linux 的 fork 函数与 Windows 的 CreateProcess 相比——复制了什么?

c - 在方法内部初始化 char 指针