What does ANSI C say about short circuit evaluation?

David E. O'Brien xc215119 at seas.gwu.edu
Sun May 26 12:05:47 AEST 1991


In article <1991May22.092404.25297 at ucthpx.uct.ac.za> gram at uctcs.uucp (Graham Wheeler) writes:
>The following question has caused a bit of debate here in the last couple of
>days. There are two parts:
>
>i) Does ANSI C say that compilers can rearrange the order of expression 
>	evaluation?
>
>ii) Does it say that Boolean expressions must be evaluated with short-
>	circuit evaluation?
>

Yes, ANSI C requires boolean short circuiting and that the C compiler must
process if(...) in the order from left to right.  In fact you can read this
from K & R 2nd ed.  They even say that many, many C programmers DEPEND on
this fact and in your life as a programmer you are probably going to come
upon some code that depends on this, so get used to it.

-- David O'Brien



More information about the Comp.lang.c mailing list