This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/19798] New: Prefix ++ doing wrong in an addition


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]