Expression sequencing query

Jason Zions jason at hpcnoe.UUCP
Sun Sep 28 10:29:31 AEST 1986

Dale Worley (drw at cullvax.UUCP) writes:

    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.  I
    don't know what the ANSI standard says.

Unfortunately, he didn't read far enough into section 7.11, or he would have
seen the following passage:

    The original description of C specified that subexpressions may be
    evaluated in any order ... The matter of interleaving was not
    discussed... We advise implementors to adhere rigidly to the
    restrictions outlined here...

In this passage, H&S state very clearly that the restriction on interleaving
is one they have added, and that the restriction did not exist in prior

In short, a C compiler implemented under K&R rules does indeed permit side-
effect evaluation in any order. Pure PCC-based compilers belong in this class.
I personally agree with H&S; it's an ugly thing to do. Of course, H&S also
	We also advise programmers not to exploit these restrictions too

which I would contend the original example does. As I have said before, people
who use more than one side-effect on the same variable in a single statement
deserve everything they get.

Could one of the true C wizards (I'm still in training, sort of...) come up
with a general statement of "things to avoid doing" to keep from getting
bitten by this interleaving bug? The statement I make in the previous para-
graph is a first cut, but I recognize that it is both too restrictive and
insufficiently restrictive to avoid the problem.
Jason Zions				Hewlett-Packard
Colorado Networks Division		3404 E. Harmony Road
Mail Stop 102				Ft. Collins, CO  80525

More information about the Comp.lang.c mailing list