public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/51562] New: Expression evaluation with commas seems incorrect in gcc 4.5.2, 4.4.4
@ 2011-12-15  7:10 willus0 at hotmail dot com
  2011-12-15 10:03 ` [Bug c/51562] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: willus0 at hotmail dot com @ 2011-12-15  7:10 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: willus0@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??


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-16 15:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15  7:10 [Bug c/51562] New: Expression evaluation with commas seems incorrect in gcc 4.5.2, 4.4.4 willus0 at hotmail dot com
2011-12-15 10:03 ` [Bug c/51562] " rguenth at gcc dot gnu.org
2011-12-15 13:27 ` willus0 at hotmail dot com
2011-12-15 15:19 ` [Bug c/51562] missing -Wsequence-point warning for expression with commas manu at gcc dot gnu.org
2011-12-16 14:12 ` willus0 at hotmail dot com
2015-03-16 15:32 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).