C optimizer
Peter Desnoyers
desnoyer at Apple.COM
Tue Mar 21 07:05:34 AEST 1989
In article <21652 at agate.BERKELEY.EDU> bowles at eris.berkeley.edu (Jeff A. Bowles) writes:
>>>> In article <1028 at frog.UUCP> john at frog.UUCP (John Woods) writes:
>>> [various people arguing whether getpid() is pure]
>>
>Are we still on this topic? By the bogosity above, nothing is "pure",
>because you might write a function that changes the behaviour of another
>function - for example, [...]
I beg to differ. I would consider that any "pure" function that does
not take arguments to be a constant, as otherwise it cannot depend
solely on its arguments, but must return a value dependent on state
information external to the function.
How about these definitions:
(note that I am considering "implicit" results, e.g.
status = f(arguments,&result) style calls return two results.)
pure - if f is pure and f takes arguments Ai and returns results Ri,
then for any action B which does not modify A or R:
R=f(A),B,R=f(A) is equiv. to R=f(A),B
is equiv. to B,R=f(A)
conditionally pure - if f is conditionally pure, then one can define
a dependency set D such that if B is some action with does
not modify A or R, and does not contain any elements of D,
then R=f(A),B,R=f(A) is equiv. to R=f(A),B is equiv. to
B,R=f(A).
It is a lot simpler for a compiler to take advantage of pure functions
than conditionally pure ones, because it doesn't have to worry about
dependencies.
Peter Desnoyers
More information about the Comp.lang.c
mailing list