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有些低级了

Advertisements

2 Comments »

  1. shuo said

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

  2. pilot said

    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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: