[comp.lang.c] Function call optimization

rob@raksha.eng.ohio-state.edu (Rob Carriere) (02/17/89)

In article <3918@ece-csc.UUCP> jnh@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