User account creation filtered due to spam.

Bug 13403

Summary: postfix ++ messes up the equation
Product: gcc Reporter: Pasi <gcc>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs
Priority: P2    
Version: 3.3.1   
Target Milestone: ---   
Host: sparc-sun-SunOs 5.8 Target: sparc-sun-SunOs 5.8
Build: sparc-sun-SunOs 5.8 Known to work:
Known to fail: Last reconfirmed:

Description Pasi 2003-12-15 17:29:02 UTC
Create and compile a simple program:
#include <iostream>
int main(){
      int i=0;
      i = 6+ i++ + 2000;
      std::cout << i << std::endl;
      return 0;
}

when running, it results "1" even when it should result "2006". If I remove the 
postfix operation "i++" the result is correct("2006"). As long as I keep 
that "i++" inside the equation I can divide, multiply, substract or add what 
ever I like, and the result is allways "1". ( There is exeption: Dividing with 
zero, creates warning and the result program craches like it should do. )

example: If the equation is
i = (6+ i++ + 2000)/2;
then "i" is still the same 1.

If I replace the postfix "i++" with prefix "++i" then the equation is 
calculated correctly, but the meaning is different( as you know prefix and 
postfix adding have different behaviour)).
Comment 1 Falk Hueffner 2003-12-15 17:46:35 UTC
You are modifying i twice without an intervening sequence point, which is
invalid. See the documentation on -Wsequence-point.
Comment 2 Wolfgang Bangerth 2004-08-05 14:57:11 UTC
Reopen these bugs... 
Comment 3 Wolfgang Bangerth 2004-08-05 15:01:48 UTC
...mark as duplicate of PR 11751. 

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