Unnecessary Macros (was Re: Unnecessary Parenthesis)

Doug Gwyn gwyn at smoke.ARPA
Fri Oct 7 02:53:09 AEST 1988


In article <716 at accelerator.eng.ohio-state.edu>, rob at kaa.eng.ohio-state.edu (Rob Carriere) writes:
> 2) I used the ``square'' macro, because that was the original example.
>    I agree that what is needed is a way of doing small integer powers
>    in general, but that just changes the problem to: why can't I write
>    power( sin(x), 2 ) [1] or some such.
> [1] not pow( sin(x), 2).  I want something that will become 1
>     evalution of sin(x) and 1 multiply.

Ah, now we get down to the real functional need.
If you use a "static" function for this, a really good optimizing
compiler can (a) turn the "pure" function into an in-line expansion
and (b) use the constant 2 or whatever to unroll the loop.  This is
a round-about way of obtaining the effect that a Fortran compiler
could also do at compile time for an instance of its ** operator.
Many C compilers aren't that good but a couple seem to come close
enough that maybe they would produce code as good as Fortran.



More information about the Comp.lang.c mailing list