Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!purdue!haven!ncifcrf!nlm-mcs!adm!smoke!gwyn From: gwyn@smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Unnecessary Macros (was Re: Unnecessary Parenthesis) Message-ID: <8644@smoke.ARPA> Date: 6 Oct 88 16:53:09 GMT References: <2089@ssc-vax.UUCP> <441@kaon.uchicago.edu> <1401@devsys.oakhill.UUCP> <716@accelerator.eng.ohio-state.edu> Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 16 In article <716@accelerator.eng.ohio-state.edu>, rob@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.