short circuit evaluation

michael at crlt.UUCP michael at crlt.UUCP
Sun Feb 22 07:21:49 AEST 1987


[Line eater shouldn't eat: no leading whitespace - but why take chances?]

In article <7610 at utzoo.UUCP>, henry at utzoo.UUCP writes:
> 
> I should add that X3J11 has come down quite firmly on the pragmatic side
> of this issue.  With the obvious exceptions of && and friends, which are
> explicitly short-circuited, the compiler is not permitted to leave out
> side effects of expressions.

Let me applaud X3J11 on this issue.  Regardless of whether side-effects
are allowed to be optimized out or not, conforming compilers should all
do things predictable from the standard.  Thus they should all either
squeeze them out or not.  Otherwise you can all-too-easily write code
that works with some conforming compilers and not others - which is
exactly what a standard is intended to prevent, or at least reduce and
make it easy to avoid.

When a programmer writes a statement with side-effects, it is probably
because he wanted them to happen.  Therefore, the logical choice is to
force the compiler to let them happen, rather than to force it to squeeze
them out.

(In the same vein, perhaps my biggest objection to c is the possibility
that associative operators may be rearranged, even if I try to coerce
the order with parenthesis.  This means that if, say, I want to coerce
multiplies and divides into a certain order to insure against overflow,
I must break expressions into several statements.)

===========================================================================
  "I've got code in my node."	| UUCP:  ...!ihnp4!itivax!node!michael
				| AUDIO: (313) 973-8787
	Michael McClary		| SNAIL: 2091 Chalmers, Ann Arbor MI 48104
---------------------------------------------------------------------------
Above opinions are the official position of McClary Associates.  Customers
may have opinions of their own, which are given all the attention paid for.
===========================================================================



More information about the Comp.lang.c mailing list