Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!cmcl2!yale!decvax!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: Re: Re: Expression sequencing query Message-ID: <602@dg_rtp.UUCP> Date: Mon, 29-Sep-86 18:07:43 EDT Article-I.D.: dg_rtp.602 Posted: Mon Sep 29 18:07:43 1986 Date-Received: Fri, 3-Oct-86 00:37:13 EDT References: <760@oakhill.UUCP> <111@titan.UUCP> <353@cullvax.UUCP> Lines: 40 > drw@cullvax.UUCP (Dale Worley) >> tomc@oakhill.UUCP (Tom Cunningham) >> /* a = b + b + b */ >> a = ((b=1),b) + ((b=2),b) + ((b=3),b) >> >> I expected the result to be 6. > Harbison&Steele (7.11) makes it clear that an implementation must > evaluate one argument of a binary operator completely before starting > evaluation of the other argument. Thus, the result should be 6. True. But note what H&S say at the end of section 7.11: The matter of interleaving was not discussed [in the original description of C...] We advise implementors to adhere [to the non-interleaving rule.] We also advise programmers not to exploit [this rule] too cleverly. And, as we have seen, their second bit of advice was well taken, since their first bit of advice seems to have been ignored in almost all implementations. > I don't know what the ANSI standard says. And the clincher is that ANSI didn't go along with H&S on this point. They say that expressions separated by "sequence points" may not be interleaved. These sequence points occur between "full expressions". Full expressions are initializers, expression statements, expressions in "if", "while" and the like, and expressions in "return". (I suspect that (?:) and (,) expressions have sequence points also, but couldn't find this on a trivial inspection of the draft standard.) Thus, ANSI C says that 9 is as good as 6, and repudiates H&S. So it goes. -- Sometimes I think the only universal in the computing field is the fetch-execute cycle. --- Alan J. Perlis -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw