User account creation filtered due to spam.

Bug 19798 - Prefix ++ doing wrong in an addition
Summary: Prefix ++ doing wrong in an addition
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-07 00:04 UTC by ceniza666
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***