c/6409: C comma operator: wrong behavior
Suanhsi Yong
suan@cs.wisc.edu
Mon Apr 22 10:26:00 GMT 2002
>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:
More information about the Gcc-bugs
mailing list