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/