C optimizer

Karl Heuer karl at haddock.ima.isc.com
Wed Feb 15 07:46:56 AEST 1989


In article <13134 at steinmetz.ge.com> davidsen at crdos1.UUCP (bill davidsen) writes:
>One solution would be to provide a keyword ... which would indicate that a
>procedure always returns the same value for a set of given arguments.  Note
>that this is not the same thing a "no side effects," my intent is only that a
>second call with the same arguments would not change the side effects (such
>as saving one of the arguments, etc).

If the concept is to be useful, it had better mean "no observable side effects
AT ALL".  The (IMHO) useful optimization of
	extern int __pure abs();
	x = abs(t);  y = abs(u);  z = abs(t);  return (z-x);
into
	return (0);
seems to be forbidden by your weaker form.

>I am not sure that having the compiler "know about" library functions is a
>good idea, since the user could provide functions with identical names if the
>compile were to be used in a non-hosted application.

No problem; such a compiler, when used in freestanding mode, simply disables
such knowledge.  This is automatic if the "magic" is embedded in the standard
header files, via a keyword.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list