Unnecessary Macros (was Re: Unnecessary Parenthesis)

steve steve at oakhill.UUCP
Thu Oct 6 01:07:52 AEST 1988


<1401 at devsys.oakhill.UUCP> <8629 at 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)
----------------------------------------------------------------------------



More information about the Comp.lang.c mailing list