a=(b=1,b)+(b=2,b)+(b=3,b); /*ANSI does NOT say a=6*/

Wayne Throop throopw at dg_rtp.UUCP
Fri Oct 3 01:20:39 AEST 1986

Some folks have said that since (,) expressions are sequence points,
the result of the expression in the Subject: line must be 6.
I don't think so.  I could be wrong, but it seems pretty straightforward
to me.  Take this example:


Now, the way I read ANSI, the sequence points at the (,) expressions
prohibit the interleaving of the evaluation of e1 and e2, and similarly
prohibits the interleaving of e3 and e4.  But it does *NOT* (as far as
I can tell) prohibit the interleaving of e1 and e3, e1 and e4, e2 and e3,
or e2 and e4.  Thus, in the example that started the whole thing (the
expression in the Subject: line) the result could legitimately be anything
from 3 to 9, inclusive.

It is true that Harbison and Steele proposed a more restrictive set of
interleaving prohibitions.  These were *NOT* adopted by ANSI.  And,
perhaps more importantly, they were never implemented by most compilers.
Therefore, it is unwise to expect the H&S recommended behavior, since
most compilers do not adhere to it, and it is *INCORRECT* to say that
compilers that do not adhere to it are "buggy" or "broken", since both
K&R and the ANSI standard disagree with H&S on this point.

At one point I thought it would be easier to rewrite all my books
without using the letter 's'.
                                 --- D.E. Knuth
Wayne Throop      <the-known-world>!mcnc!rti-sel!dg_rtp!throopw

More information about the Comp.lang.c mailing list