This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13403] New: postfix ++ messes up the equation
- From: "gcc at lantiainen dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Dec 2003 17:29:03 -0000
- Subject: [Bug c++/13403] New: postfix ++ messes up the equation
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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