Bug 13403 - postfix ++ messes up the equation
Summary: postfix ++ messes up the equation
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2003-12-15 17:29 UTC by Pasi
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

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


Note You need to log in before you can comment on or make changes to this bug.
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 ***