c/7479: wrong arithmetic output

olivier.baudron@m4x.org olivier.baudron@m4x.org
Sat Aug 3 09:06:00 GMT 2002


>Number:         7479
>Category:       c
>Synopsis:       wrong arithmetic output
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 03 09:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     olivier.baudron@m4x.org
>Release:        gcc-3.1.1
>Organization:
>Environment:

>Description:
The following testcase produces a wrong output:

#include <stdio.h>
int f() { return 1; }
int main(int argc, char **argv) {
    int n=1, a, b;
    a = (1 | (2 - f())) | (-n);
    b = (1 | (2 - 1))   | (-n);
    printf("a=%d b=%d\n", a, b);
    return 0;
}

$ gcc -Wall -o test test.c
$ ./test 
a=1 b=-1

It should be: a=1 b=1
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list