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]

[Bug c++/13403] New: postfix ++ messes up the equation


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)).

-- 
           Summary: postfix ++ messes up the equation
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at lantiainen dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-SunOs 5.8
  GCC host triplet: sparc-sun-SunOs 5.8
GCC target triplet: sparc-sun-SunOs 5.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13403


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