Bug 19798

Summary: Prefix ++ doing wrong in an addition
Product: gcc Reporter: ceniza666
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs
Priority: P2    
Version: 3.4.3   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description ceniza666 2005-02-07 00:04:39 UTC
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;".
Comment 1 Paolo Carlini 2005-02-07 00:19:08 UTC

*** This bug has been marked as a duplicate of 11751 ***