RE: C and side-effects

From: Andrew G. Gilpin (agg1@cec.wustl.edu)
Date: Wed May 03 2000 - 22:27:48 EST


On 4 May 2000, Robert M. Love wrote:
> maybe im reading the thread wrong, but Cesar is saying the code
> while ((mm->swap_cnt << 2 * (i + 1) < max_cnt) && i++ < 10)
> does not guarentee that the expression to the left of && occurs prior to
> "i++" -- and he is Right,
> because the C standard does *not* specify this. proof is in K&R, where they
> explicitly mention compiler design or optimization can change compound
> statement ordering in the resulting machine code. thus, i agree an
> alternative should be considered in the kernel.

If a compiler compiles code so that the "i++" executes before the code to
the left of the && then the compiler is busted, plain and simple. This is
a feature of C sometimes referred to as "short-circuiting". I am certain
that the "compiler design or optimization" that K&R are talking about does
not apply here.

-Andrew

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:13 EST