This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/7479: wrong arithmetic output


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]