This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/19798] New: Prefix ++ doing wrong in an addition
- From: "ceniza666 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Feb 2005 00:04:41 -0000
- Subject: [Bug c/19798] New: Prefix ++ doing wrong in an addition
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
A program as simple as:
int b = 10;
int a;
a = (++b) + (++b) + (++b);
printf("%d", a);
shows the wrong answer.
It should be 36, it shows 37. Optimisations on or off throw the same result.
Source of the problem: Generated code.
Pseudo C/asm code:
++b;
++b;
%eax = b;
%edx = b;
%edx += %eax;
++b;
%edx += b
a = %edx
So, when it should be doing "a = 11 + 12 + 13;" it's doing "a = 12 + 12 + 13;".
--
Summary: Prefix ++ doing wrong in an addition
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ceniza666 at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19798