public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/3165: ANSI C standard violation
@ 2001-06-13 5:36 tczarnecki
0 siblings, 0 replies; 2+ messages in thread
From: tczarnecki @ 2001-06-13 5:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 3165
>Category: c
>Synopsis: ANSI C standard violation
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Wed Jun 13 05:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Tomasz Czarnecki
>Release: unknown-1.0
>Organization:
>Environment:
Sun Solaris 2.6 (Sparc)
>Description:
The order of expression evaluation is bad. The example code produces output like that:
1, a=1, b=1, c=1
2, a=1, b=1, c=1
3, a=1, b=1, c=1
11, a=3, b=2, c=1
1, a=1, b=1, c=1
2, a=1, b=1, c=1
3, a=1, b=1, c=1
22, a=2, b=1, c=1
1, a=1, b=1, c=1
2, a=1, b=1, c=1
3, a=1, b=1, c=1
33, a=1, b=1, c=1
But it should look like:
3, a=1, b=1, c=1
2, a=1, b=1, c=1
1, a=1, b=2, c=1
11, a=3, b=2, c=1
2, a=1, b=1, c=1
3, a=1, b=1, c=1
1, a=1, b=1, c=1
22, a=2, b=1, c=1
3, a=1, b=1, c=1
2, a=1, b=1, c=1
1, a=1, b=1, c=1
33, a=1, b=1, c=1
It looks like exressions are evaluated first and then operators are applied. But I don't think it should work that way. Microsoft VC 6.0 compiler has some problems too but only += like operators case an error. In this case output looks like:
1, a=1, b=1, c=1
2, a=1, b=1, c=1
3, a=1, b=1, c=1
11, a=3, b=2, c=1
2, a=1, b=1, c=1
3, a=1, b=1, c=1
1, a=1, b=1, c=1
22, a=2, b=1, c=1
3, a=1, b=1, c=1
2, a=1, b=1, c=1
1, a=1, b=1, c=1
33, a=1, b=1, c=1
>How-To-Repeat:
/*Compile this file with no options*/
#include <stdio.h>
foo(int n, int a, int b, int c)
{
printf("%d, a=%d, b=%d, c=%d\n", n, a, b, c);
}
int main()
{
int a=1, b=1, c=1;
*(foo(1, a, b, c), &a) += *(foo(2, a, b, c), &b) += *(foo(3, a, b, c), &c);
foo(11, a, b, c);
a=1, b=1, c=1;
*(foo(1, a, b, c), &a) = *(foo(2, a, b, c), &b) + *(foo(3, a, b, c), &c);
foo(22, a, b, c);
a=1, b=1, c=1;
*(foo(1, a, b, c), &a) = *(foo(2, a, b, c), &b) = *(foo(3, a, b, c), &c);
foo(33, a, b, c);
return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c/3165: ANSI C standard violation
@ 2001-06-13 6:19 jsm28
0 siblings, 0 replies; 2+ messages in thread
From: jsm28 @ 2001-06-13 6:19 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, jsm28, nobody, tczarnecki
Synopsis: ANSI C standard violation
State-Changed-From-To: open->closed
State-Changed-By: jsm28
State-Changed-When: Wed Jun 13 06:19:09 2001
State-Changed-Why:
Not a bug. Re-read the C standard, in particular the rules
on sequence points. Your program has undefined behavior.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3165&database=gcc
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-06-13 6:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-13 5:36 c/3165: ANSI C standard violation tczarnecki
2001-06-13 6:19 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).