short circuit evaluation

chris at mimsy.UUCP chris at mimsy.UUCP
Mon Jan 26 12:24:19 AEST 1987


In article <621 at sdchema.sdchem.UUCP> tps at sdchem.UUCP (Tom Stockfisch) writes:
>"&" and "|" are like "+" and "-" in that you are not guaranteed that
>the left side will be [fully] evaluated before the right [or vice versa].
>Read K&R sections 7.8-10, p. 190:
>	"The [&|^] operator is associative and expressions involving [&|^]
>	may be rearranged." 

This is a good point too.  It gets worse all the time! :-)

>I agree with you that the evaluation might be short circuited if the result
>is already known.  However, I don't think this is guaranteed,

Of course not.  Intuitive languages make few guarantees.... :-)

>it might happen in the reverse order (right operand evaluated,
>left operand skipped),

That was one of the possibilities I enumerated.

>and it is guaranteed not to happen if the to-be-skipped operand has a
>side effect.

Is it?

(This is one reason optimising compilers are so difficult to write:
No one is sure just how much they are allowed to do....)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list