c - INT_MIN % -1 会产生未定义的行为吗?

标签 c gcc overflow division modulo

gcc 为以下代码生成引发 SIGFPE 的 float 代码:

#include <limits.h>
int x = -1;
int main()
{
    return INT_MIN % x;
}

但是,我在标准中找不到声明此代码调用未定义或实现定义的行为的声明。据我所知,它需要返回 0。这是 gcc 中的错误,还是我遗漏了标准产生的一些特殊异常?

最佳答案

您可能是对的,这可以被视为实际标准中的错误。 current draft解决这个问题:

If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a; otherwise, the behavior of both a/b and a%b is undefined.

关于c - INT_MIN % -1 会产生未定义的行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5925045/

相关文章:

c - 如何更改 intel cpu 中的智能缓存功能?

gcc - 在内联汇编中使用 double 字 (GCC, IA-32)

css - inline-block 流体布局,子内容不会展开父容器

c - printf ("%s",*&*str) 的输出是什么? str 中的哪里是指针?

c - 编写获取下一个标记函数

c - gcc 的内存对齐警告

c++ - Netbeans 中的 "make[2]: g++: Command not found"

c++ - 隐式提升以避免 std::partial_sum 溢出

程序集 8086 - 发生溢出

CUDA 纹理内存绑定(bind)全局内存的子部分