http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51562

             Bug #: 51562
           Summary: Expression evaluation with commas seems incorrect in
                    gcc 4.5.2, 4.4.4
    Classification: Unclassified
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: will...@hotmail.com


I apologize if this has been reported or isn't even a bug, but I wasn't even
sure what to search for.  The code below doesn't evaluate the way you think it
might in gcc 4.5.2 (and gcc 4.4.4).  I'm not even sure how it should
legally/correctly evaluate, but there is a powell() function in Numerical
Recipes in C (1st and 2nd editions) that uses code like below and expects the
answer to the second line to be 5 (i.e. for the x*x expression to be evaluated
with the two different values of x and summed correctly).  That's how I
discovered this issue.  gcc-compiled code in gcc 4.5.2/4.4.4 reports this:

1+2=4
1^2+2^2=8

I tried different levels of optimization, on both Linux and Windows (MinGW),
all with the same result.  Tiny CC-compiled code reports this:

1+2=4
1^2+2^2=5

Those are the only compilers I've tried.  Here's the program:

#include <stdio.h>
void main(void)
    {
    int x;
    printf("1+2=%d\n",(x=1,x)+(x=2,x));
    printf("1^2+2^2=%d\n",(x=1,x*x)+(x=2,x*x));
    }

Thoughts??

Reply via email to