iptton 发表于 2007-11-19 22:35

-10==10?

原地址:http://linux.solidot.org/article.pl?sid=07/11/19/0512218&from=rss
bhpan 写道 "linux程序不能区分正数和负数,例如,-10和10会被认为是相等的。真的是这样吗?试试以下的C代码:int main () {
                int i=2;
                if( -10*abs (i-1) == 10*abs(i-1) )
                              printf ("OMG,-10==10 in linux!\n");
                else
                              printf ("nothing special here\n");
}
同样的C代码,在windows和unix系统中编译运行的结果是nothing special here,只有linux得到是-10==10。
恩,我们的gcc在这里犯了一个低级错误。"

iptton 发表于 2007-11-20 00:48

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34130

------- Comment #4 From Richard Guenther2007-11-17 14:23 -------

Fixed on the trunk.

powerwind 发表于 2007-11-20 22:09

http://blog.csdn.net/Raptor/archive/2007/11/19/1893079.aspx

我猜是abs的问题,原来是编译器优化原因
页: [1]
查看完整版本: -10==10?