pure functions are tricky

Brian Westley merlyn at ernie.Rosemount.COM
Wed Feb 22 01:39:12 AEST 1989


Legend:
>>Me
>Doug Gwyn

>>Now, should it be possible to fold pure functions with constant arguments?
>>	x = sin(sqrt(2.0)) ;	/* turns into simple assignment to a constant? */
>
>Sure.  Why not?...

But then I asked -
>>What about pure functions that can only be evaluated at run time, such as a
>>function that returns the name of the machine the program is running on?

This was my main point: there are functions which return the same results
for the same arguments, without side-effects, which can't be folded at
compile time if given constant arguments.

If such functions are not considered pure, they won't be optimized.

If such functions are considered pure, not all pure functions will be
foldable into constants.  Either you have to tell the compiler which is
which, or the compiler has to figure it out (not bloody likely).

-----
Merlyn LeRoy
#pragma ivory /* 99 44/100% pure */



More information about the Comp.lang.c mailing list