Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cs.utexas.edu!oakhill!steve From: steve@oakhill.UUCP (steve) Newsgroups: comp.lang.c Subject: Re: Unnecessary Macros (was Re: Unnecessary Parenthesis) Summary: Let's get back to the roots of the discussion. Message-ID: <1527@devsys.oakhill.UUCP> Date: 5 Oct 88 15:07:52 GMT References: <2089@ssc-vax.UUCP> <441@kaon.uchicago.edu> Organization: Motorola Inc. Austin, Tx Lines: 40 <1401@devsys.oakhill.UUCP> <8629@smoke.ARPA> In case you don't remember, I was the one who first brought up the use of temp in this discussion. At that point in time the discussion was the technique on writing macros, not the technique on writing the macro square. Most comments on why square is not sane to write this way miss the point of the original discussion. Square was just a trivial example. A similar macro I have used have involved setting bit fields, where the variable holding the bit also is needed later in the bit field calculation. Using a macro to do this covers up a messy equation, and makes it more obvious what going on. Now lets get back to the original discussion. As I pointed out at that time, the use of temp was not optimal. The two big draw backs are : 1) It is inefficient. Thus should be used only in the case where a change in a variable in the equation is likely and will change the result (square(x++)), or where the variable could be an expression that is costly to calculate (square((cos(x)/sin(x))). 2) the use of a temp which must be supplied. The second I have gotten around by suppling the temp as a parameter to the macro (as someone has mentioned and I was remiss in not mentioning. (I figured everyone would see this problem, and be able to program around it their own way) The major point of my posting was two-fold. First to warn people they need to think before they macro-ed. And also to point out that the proposed solution had drawbacks. I conclude with the statement I concluded my last posting with : > Use your best judgement - macros are dangerous thing if not used carefully > That is why C compilers have a -P option. enough from this mooncalf - Steven ---------------------------------------------------------------------------- These opinions aren't necessarily Motorola's or Remora's - but I'd like to think we share some common views. ---------------------------------------------------------------------------- Steven R Weintraub cs.utexas.edu!oakhill!devsys!steve Motorola Inc. Austin, Texas (512) 440-3023 (office) (512) 453-6953 (home) ----------------------------------------------------------------------------