Function call optimization (was: Re: C optimizer)

Rob Carriere rob at raksha.eng.ohio-state.edu
Fri Feb 17 03:07:24 AEST 1989


In article <3918 at ece-csc.UUCP> jnh at ece-csc.UUCP (Joseph Nathan Hall) writes:
>Now, you know, this is an interesting point.  The functions (call them
>"pure" or "mathematical") that can be optimized in the fashion of redundant
>subexpressions have to depend SOLELY on their inputs, and furthermore
>(this is the point) can't have any "memory" of previous state.

Memofunctions form a useful counterexample to this claim.  A
memofunction behaves exactly like its pure function counterpart,
except that it uses a memory of previous calls to speed up the
calculations. 

>The function rand() would be OK [as a pure function] if it required a
>seed value as a parameter.

Only if you are willing to manually change the seed between calls.
You'll need a second (non-pure) function for this, which kind of
defeats the purpose of the excersize.

SR



More information about the Comp.lang.c mailing list