User account creation filtered due to spam.

Bug 15103

Summary: postincrement precedence lower than assignment
Product: gcc Reporter: Mark <musicman529>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Severity: minor CC: gcc-bugs
Priority: P2    
Version: 3.3.3   
Target Milestone: ---   
Host: i486-slackware-linux Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Mark 2004-04-23 18:13:35 UTC
In the following program:
#include <stdio.h>
int main(int argc, char *argv[]) {
  int x = 20, y = 35;
  x = x++ + y++;
  y = ++x + ++y;
  printf("x=%d y=%d\n", x, y);
  return 0;

In the first assignment line "x = x++ + y++;", the code emitted by the i386
compiler processes the post-increment operators after the assignment, so that
the addition result gets incremented in "x".

1. Shouldn't "x++" be semantically equivalent to "(x += 1, x - 1)"? The first
assignment produced assembly that behaved more like:
x = x + y;
I tried to use parentheses around the increment expressions to force the
precedence, but they were ignored.

2. Don't the increment and decrement operators have a much higher precedence
than assignment?

I'll admit, any coder working for me who wrote code like the above, would be
fired on the spot. This is a very small corner case. However, it may point to a
larger issue that needs to be resolved, so I'm filing it "just in case".
Comment 1 Falk Hueffner 2004-04-23 18:57:49 UTC
Invalid, since you're modifying variables twice without a sequence point in
between. Please read the documentation on -Wsequence-point.
Comment 2 Wolfgang Bangerth 2004-08-05 14:57:10 UTC
Reopen these bugs... 
Comment 3 Wolfgang Bangerth 2004-08-05 15:01:23 UTC
...mark as duplicate of PR 11751. 

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