Bug 3324

Summary: wrong operator priority
Product: gcc Reporter: arminu
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs, neil
Priority: P3 Keywords: wrong-code
Version: 3.0.1   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description arminu 2001-06-21 04:36:01 UTC
the prefix increment operator is not correctly evaluated in the following code:

int a[8];
int i = 4;
a[i] = ++i;

the last line is evaluated as 
a[4] = 5;
instead of 
a[5] = 5;

Release:
2.95-2, 2.95-3, 2.96, 3.0.1 20010620

Environment:
mingw port (2.95-2, 2.95-3), RedHat Linux 7.1 gcc compiler (2.96-??), CodeSourcery online test compilation(3.0.1 20010620 )

How-To-Repeat:
void test(void)
{
int a[8] = {0,0,0,0,0,0,0,0};
int i = 4;
a[i] = ++i;
printf("\na[4] = %d\na[5] = %d\n", a[4], a[5]);
}
Comment 1 Neil Booth 2001-06-21 04:59:59 UTC
State-Changed-From-To: open->closed
State-Changed-Why: This is not a bug - your code has undefined behaviour
    as there is no sequence point between the two uses.
Comment 2 Andrew Pinski 2005-04-20 02:55:05 UTC
Reopening to ...
Comment 3 Andrew Pinski 2005-04-20 02:55:25 UTC
Mark as a dup of bug 11751.

*** This bug has been marked as a duplicate of 11751 ***