public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/6409: C comma operator: wrong behavior
@ 2002-04-22 10:06 Suanhsi Yong
  0 siblings, 0 replies; 2+ messages in thread
From: Suanhsi Yong @ 2002-04-22 10:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6409
>Category:       c
>Synopsis:       C comma operator: wrong behavior
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 22 10:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Suanhsi Yong
>Release:        3.0.3
>Organization:
>Environment:
System: Linux cygnet.cs.wisc.edu 2.4.17-csl1smp #1 SMP Mon Jan 7 16:44:21 CST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /s/gcc-3.0.3/src/gcc-3.0.3/configure --prefix=/s/gcc-3.0.3/i386_rh72 --enable-shared --enable-threads

Note: bug also manifested in <sparc-sun-solaris2.8> version, and version 3.0.4 (linux) as well.

>Description:
	Best illustrated by example:

	1.  int val;
	2.  (val=11)
	3.  + (val=22,
	4.     printf("VAL = %d\n", val)
	5.    );

	Line 4 outputs "11" rather than the expected "22".

	C specs define a sequence point at the comma operator,
	so by the "at-most-one-write" semantics of expressions,
	val should be 22 at line 4.
	(Its value at line 6, of course, is undefined, due to
	 the arbitrary order-of-evaluation for the + operator.)

>How-To-Repeat:
	Just compile (gcc, no special flags needed) and run the following:

	int main()
	{
	  int val;

	  (val=11)
	  + (val=22, printf("VAL = %d\n", val));

	  return 0;
	}

>Fix:
	Don't know.
>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c/6409: C comma operator: wrong behavior
@ 2002-04-22 10:16 jsm28
  0 siblings, 0 replies; 2+ messages in thread
From: jsm28 @ 2002-04-22 10:16 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, jsm28, nobody, suan

Synopsis: C comma operator: wrong behavior

State-Changed-From-To: open->closed
State-Changed-By: jsm28
State-Changed-When: Mon Apr 22 10:16:11 2002
State-Changed-Why:
    Sequence points define a partial ordering, not a total
    ordering.  There is no ordering in the example between
    (val=11) and any part of the other argument of +.  Both
    arguments of the comma operator conflict with (val=11),
    causing undefined behavior if this code is ever executed
    (so the compiler can make deductions on the basis that
    it never will be executed).

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6409


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

end of thread, other threads:[~2002-04-22 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-22 10:06 c/6409: C comma operator: wrong behavior Suanhsi Yong
2002-04-22 10:16 jsm28

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).