Evaluation order (`&&') (was: Re: C style)

Chris Torek chris at umcp-cs.UUCP
Fri Nov 1 10:33:37 AEST 1985


In article <538 at ttrdc.UUCP> levy at ttrdc.UUCP (Daniel R. Levy) writes:

> The && operator doesn't GUARANTEE the chronological order of evaluation
> is going to be left to right,

No.  && and || are guaranteed to evaluate the left hand side of
the expression, and if the result is false or true (respectively)
stop, otherwise evaluate the right hand side.  (These are `McCarthy'
or short-circuiting expressions.)  This is why

	if (p == NULL || *p == 0)

is guaranteed not to crash even on a machine where *(type *)NULL
will.

> if you have a screwball compiler (though it most probably will be).

If you change that to `a broken compiler' I will agree.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list