Article View: net.lang.c
Article #9423Re: Expression sequencing query
From: Fabbian G. Dufoe
Date: Mon, 29 Sep 1986 18:56
Date: Mon, 29 Sep 1986 18:56
53 lines
2152 bytes
2152 bytes
In article <111@titan.UUCP>, eectrsef@titan.UUCP writes:
> In article <760@oakhill.UUCP> tomc@oakhill.UUCP (Tom Cunningham) writes:
> > /* a = b + b + b */
> > a = ((b=1),b) + ((b=2),b) + ((b=3),b)
> >
> >I expected the result to be 6. With the Microsoft C compiler and the
> >compiler on the Sun 3, the result is 9. Apparently the parenthetical
> >assignments are all getting done before the comma and addition. Any
> >thoughts on this?
> >
> Tom, I agree, the result should be 6, as defined by K&R, but I have tried
> it on a Cyber 180/830 running NOS VE, and get 9, also AT&T's 3B5
> System V, gets 9.
> I would like everyone to test it on as many machines as prossible, to
> see if we can find as least ONE other besides Small-C, that works.
>
> Mike Stump ucbvax!hplabs!csun!csunb!beusemrs
I compiled the following code on an AT&T 3B2 (System V) and an
Amiga (Lattice 3.03):
main()
{
int a, b;
a = ((b=1),b) + ((b=2),b) + ((b=3),b);
printf("%d\n", a);
a = (b=1) + (b=2) + (b=3);
printf("%d\n", a);
a = (b=1), a += (b=2), a += (b=3);
printf("%d\n", a);
}
On the 3B2 it produced:
9
9
6
On the Amiga, surprisingly, it produced:
7
7
6
Both are wrong, but one can see where the 3B2 went wrong. How in
the world did Lattice come up with 7?
Fabbian Dufoe
350 Ling-A-Mor Terrace South
St. Petersburg, Florida 33705
813-823-2350
UUCP: ...akgua!akguc!codas!peora!ucf-cs!usfvax2!jc3b21!fgd3
Technical Details
Message-ID:
<468@jc3b21.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!codas!peora!ucf-cs!usfvax2!jc3b21!fgd3References:
<760@oakhill.UUCP> <111@titan.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!codas!peora!ucf-cs!usfvax2!jc3b21!fgd3 From: fgd3@jc3b21.UUCP (Fabbian G. Dufoe) Newsgroups: net.lang.c Subject: Re: Expression sequencing query Message-ID: <468@jc3b21.UUCP> Date: Mon, 29-Sep-86 14:56:05 EDT Article-I.D.: jc3b21.468 Posted: Mon Sep 29 14:56:05 1986 Date-Received: Tue, 30-Sep-86 14:44:19 EDT References: <760@oakhill.UUCP> <111@titan.UUCP> Distribution: net Organization: St. Petersburg Jr. College, St. Petersburg FL Lines: 53 Keywords: Bugs Summary: 3B2 running System V and Amiga running Lattice fail the test.