Unnecessary Macros (was Re: Unnecessary Parenthesis)

Scott Wilson swilson%thetone at Sun.COM
Tue Sep 27 09:16:14 AEST 1988


In article <8078 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <8577 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn) writes:
>>In article <23 at datcon.UUCP> sar at datcon.co.uk (Simon A Reap) writes:
>>>	z = square(x) + square(y);
>>>Does anyone know how to get round this problem?  Please!!
>>	z = x*x + y*y;
>
>Doug's answer is certainly a better way to write the given example, but is not
>particularly enlightening if you want
>	z = square(*p++) + square(getchar());
>
>I dislike the original macro, but the fact remains that there is no good way
>to write this in C.  (There are several bad ways, and we could argue over
>which is the least bad, but it really depends on the circumstances.)

Maybe I'm missing the point, but why does a good old fashion function seem
to be out of the question.  Or better yet, why not do it like getc/fgetc
and define a macro for square and have a function fsquare when side effects
are questionable.  And just to make it complete have another function
fdsquare to square doubles.  This way you use square when there is no
doubt and the functions when there is.  Does this sound reasonable?

--
Scott Wilson		arpa: swilson at sun.com
Sun Microsystems	uucp: ...!sun!swilson
Mt. View, CA



More information about the Comp.lang.c mailing list