Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@zoo.toronto.edu (Henry Spencer)
Subject: Re: What does ANSI C say about short circuit evaluation?
Message-ID: <1991May23.170232.6675@zoo.toronto.edu>
Date: Thu, 23 May 1991 17:02:32 GMT
References: <1991May22.092404.25297@ucthpx.uct.ac.za>
Organization: U of Toronto Zoology

In article <1991May22.092404.25297@ucthpx.uct.ac.za> gram@uctcs.uucp (Graham Wheeler) writes:
>i) Does ANSI C say that compilers can rearrange the order of expression 
>	evaluation?

Not unless it can guarantee that the results (including things like
overflow exceptions, if any) are the same.  This is a tightening-up
of the specs relative to old C.

>ii) Does it say that Boolean expressions must be evaluated with short-
>	circuit evaluation?

If you're referring to the && and || operators, C has *always* required 
short-circuit evaluation of these, and ANSI C confirms this.  If you're
referring to the & and | operators, short-circuit evaluation is forbidden
unless the results (including side effects) are exactly the same.
-- 
And the bean-counter replied,           | Henry Spencer @ U of Toronto Zoology
"beans are more important".             |  henry@zoo.toronto.edu  utzoo!henry
