Pure Functions (was Re: C optimizer)

david wald wald-david at CS.YALE.EDU
Fri Feb 17 07:39:17 AEST 1989


In article <2008 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
>From article <1398 at quanta.eng.ohio-state.edu>, by rob at kaa.eng.ohio-state.edu (Rob Carriere):
>> What seems to be missing is the idea that sleep *does* modify
>> something, namely time.  So formally speaking, your compiler should
>> consider sleep to have a side effect on a variable called __time.  If
>> you do that, there's no problem.
>
>Huh??
>
>On a time-shared system (such as Unix), does every instruction have
>a side effect on a variable called __time?

Point taken, but we still need a way to describe the difficulty with
treating sleep() as a pure function.  The actual difficulty is related
to the problem with volatile variables.  The compiler can't optimize
sleep() calls away, since they rely on some external (volatile) clock
variable (or some system call accessing this variable) for their
behavior.


============================================================================
David Wald                                              wald-david at yale.UUCP
waldave at yalevm.bitnet                                 wald-david at cs.yale.edu
"A monk, a clone and a ferengi decide to go bowling together..."
============================================================================



More information about the Comp.lang.c mailing list