Must useless expressions be evaluated?

Barry Margolin barmar at mit-eddie.UUCP
Sat Oct 15 16:33:28 AEST 1983


ether there are any side effects and whether
the value of an expression is used.

PL/I (or at least the Multics version) allows the programmer to give a
function the "reducible" attribute.  A reducible function is one which
does not have any side effects and whose value is solely a function of
the arguments (i.e., not global variables can affect the value).  The
compiler is then free to throw away excess calls, i.e. it may translate
	y = foo (x) + foo (x);
to
	y = 2 * foo (x);
and it may skip over reducible function calls in boolean expressions,
i.e.
	if bool_var | foo (x) then ...
is permitted to not evaluate foo (x) if bool_var is true.
-- 
			Barry Margolin
			ARPA: barmar at MIT-Multics
			UUCP: ..!genrad!mit-eddie!barmar



More information about the Comp.lang.c mailing list