gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:24:44 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com