Unnecessary Macros (was Re: Unnecessary Parenthesis)

Rob Carriere rob at phao.eng.ohio-state.edu
Thu Oct 6 02:59:41 AEST 1988


In article <855 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
>From article <701 at accelerator.eng.ohio-state.edu), by rob at kaa.eng.ohio-state.edu (Rob Carriere):
>)[...]
>) temp = sin( x );
>) foo = temp*temp + 1.7;
>) 
>) is clearly less legible.
>     ^^^^^^^ ^^^^ ^^^^^^^
>
>To me it is clearly much more legible, becuase I don't have to worry
>about whether "square" has side-effects!

I should have stated the assumption that ``square'' was some
well-defined system function/macro/whatever (don't leave your math
library without one!).  Otherwise, you sure have a good point.

>Always restrict the scope of variables as strictly as possible.

Amen.

>(If the compiler were smart enough to know that sin() has no side-effects,
> it could transform " foo = sin(x)*sin(x) + 1.7 " into the code I
> prefer by means of "common subexpression removal".)

Yes, but I can't rely on the compiler being smart, unless I like nasty
surprises.  Also, while I can check ``sin(x) is the same as sin(x)''
readily enough, it rapidly gets worse with more complicated
expressions.  This is essentially the same thing the *= operator
&friends solve for assignments.  In the same vein, if the expression
gets nasty enough that I need several temporaries, I may get to the
point where I can't see the expression for the temporaries.

Rob Carriere



More information about the Comp.lang.c mailing list