Unnecessary Macros (was Re: Unnecessary Parenthesis)

John Russell john13 at garfield.MUN.EDU
Tue Oct 11 09:54:06 AEST 1988


In article <1527 at devsys.oakhill.UUCP> steve at oakhill.UUCP (steve) writes:
><1401 at devsys.oakhill.UUCP> <8629 at smoke.ARPA>
>As I pointed out at that time, the use of temp was not optimal.  The two
>big draw backs are :
>  1) It is inefficient. 
>  2) the use of a temp which must be supplied.  

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.

Example:

consistent double cos();

#define square(x) ((x) * (x))

a = PI / 2.0;
b = square(cos(a));

The compiler knows "a" does not change in the expanded expression, so it uses
its own temp and only calls cos once.

Is this feasible? Doesn't sound too hard...

John
-- 
"...and intuition, in a case such as this, is of crucial importance."
			-- William Gibson, _Count_Zero_



More information about the Comp.lang.c mailing list