This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15012] New: Unexpected behaviour on i--
- From: "mdeluigi at student dot ethz dot ch" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Apr 2004 14:51:37 -0000
- Subject: [Bug c++/15012] New: Unexpected behaviour on i--
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Try that code:
---8<---
int j = 2;
int i = 2;
i = i-- + ++j;
cout << i;
--->8---
The suprising result is that i == 1.
I tried this on pc (intel), powerpc and sparc.
The result is because the compiler does something like:
---8<---
tmp1 = i--;
tmp2 = ++j;
i = i + tmp2;
i = tmp1;
--->8---
(check the asm-code for more details).
That's not what the programer expects.
--
Summary: Unexpected behaviour on i--
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mdeluigi at student dot ethz dot ch
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15012