public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "willus0 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51562] New: Expression evaluation with commas seems incorrect in gcc 4.5.2, 4.4.4 Date: Thu, 15 Dec 2011 07:10:00 -0000 [thread overview] Message-ID: <bug-51562-4@http.gcc.gnu.org/bugzilla/> (raw) 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??
next reply other threads:[~2011-12-15 4:53 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-12-15 7:10 willus0 at hotmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-51562-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).