Path: utzoo!utgpu!attcan!uunet!husc6!mailrus!uflorida!novavax!proxftl!bill
From: bill@proxftl.UUCP (T. William Wells)
Newsgroups: comp.lang.c
Subject: Re: Unnecessary Macros (was Re: Unnecessary Parenthesis)
Message-ID: <830@proxftl.UUCP>
Date: 29 Sep 88 15:29:23 GMT
References: <2089@ssc-vax.UUCP> <441@kaon.uchicago.edu> <1401@devsys.oakhill.UUCP> <23@datcon.UUCP> <8577@smoke.ARPA> <8078@haddock.ima.isc.com> <70279@sun.uucp> <1851@loral.UUCP>
Reply-To: bill@proxftl.UUCP (T. William Wells)
Organization: Proximity Technology, Ft. Lauderdale
Lines: 29
Summary:
Expires:
Sender:
Followup-To:
Distribution:
Keywords:

In article <1851@loral.UUCP> jlh@loral.UUCP (Physically Phffft) writes:
: [A long section explaining a bug easily caused by temps used in macros]
:
: The moral?  Well, if you have to use a temp variable in a macro then
: PASS the bloody thing.
:
: #define power(x,y, tmp) (tmp = x*x + y*y, x = tmp)
:
: result = power(x, y, temp);
:
: This ensures that the poor overworked sucker who ends up maintaining your
: code knows damn well that your macro requires a temp variable to work right.

We have a coding standard that makes globals always distinct from
locals: globals *always* start with a capital letter; locals,
never.  Given this, we can handle this problem with

int     Square_temp;             /* Macro only works for ints, oh well. */
#define square(x) (Square_temp = (x), Square_temp * Square_temp)

I would never do this (not without a compelling reason, anyway),
but should someone do so here, at least they'd not get bitten by
the local-global problem.

---
Bill

You can still reach me at proxftl!bill
But I'd rather you send to proxftl!twwells!bill