Another 'D' proposal (sigh)

Eric S. Raymond eric at snark.UUCP
Tue Mar 1 23:44:34 AEST 1988


In article <1893 at phoenix.Princeton.EDU>, Raymond Juimong Chen writes:
>Propose that there be a way to declare "true functions", ie, functions
>whose return values depend on and are solely determined by the arguments
>passed to it.  They also have no side-effects.

Compiler folklore (and at least one major dialect of Pascal in which you can
declare them explicitly) calls such animals 'pure' functions.

>Implementation:
>I can think of two ways this could be implemented.  Let foo() be a
>"true function".
>
>register int foo(...)
>const int foo(...)

Not a bad idea. I'd prefer 'const' because it doesn't confuse the declaration
of the function's (lack of) side-effects with the declaration of the storage
class for its return type. Another kind of optimization this would permit
would be inlining.

Of course, the ANSI people will reject this on grounds of 'no prior art',
even though it's a better and better-tested idea than 'noalias'.
-- 
      Eric S. Raymond                  (the mad mastermind of TMN-Netnews)
      UUCP:  {{seismo,ihnp4,rutgers}!cbmvax,sdcrdcf!burdvax,vu-vlsi}!snark!eric
      Post:  22 South Warren Avenue, Malvern, PA 19355    Phone: (215)-296-5718



More information about the Comp.lang.c mailing list