Unnecessary Macros (was Re: Unnecessary Parenthesis)

Haller jhh at ihlpl.ATT.COM
Thu Oct 13 00:45:21 AEST 1988


In article <4920 at garfield.MUN.EDU>, john13 at garfield.MUN.EDU (John Russell) writes:
> How about this for an addition to C: a special keyword, similar to const,
> which declares that a function which is passed identical values will always
> return the same value, and that the function has no side effects.

The information to do this is already available, and a truely optimizing
compilation system should do this.  Note that I said compilation system,
not compiler, where a makefile for a product would be the likely input.
When compiling cos(), the compiler should be able to take note of
there being no side effects, and take appropriate actions if
cos is not re-defined within an application.

In the example,
	consistent double cos();
	#define square(x) ((x) * (x))
	a = PI / 2.0;
	b = square(cos(a));

the compilation system should be able to detect that 'a' is set from
a constant, call cos(a) at compile time, perform the square are compile
time, and reduce the fragment to a=1.57..; b=0.0;, all without the need
for 'consistent'.

This optimization may be beyond the capability of current C compilers,
but we should not be introducing new keywords to solve problems that
should be solved with compilation technology in the future.

John Haller
AT&T Bell Laboratories



More information about the Comp.lang.c mailing list