gcc不能区分正数和负数

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在这里犯了一个低级错误。”

呵呵,这个bug有些低级了

2 Comments »

  1. shuo said,

    November 21, 2007 @ 11:02 pm

    似乎是intrinsic和优化部分有冲突。不过gcc生成的代码确实不太好,居然还有这样的…
    movl %eax, %edx
    movl %edx, %eax

  2. pilot said,

    December 6, 2007 @ 7:07 pm

    if I change
    if( -10*abs (i-1) == 10*abs(i-1) )
    to
    if( -10*abs (1-i) == 10*abs(1-i) )

    就不相等了,bug从哪里来的?

RSS feed for comments on this post · TrackBack URI

Leave a Comment