Unnecessary Macros (was Re: Unnecessary Parenthesis)

T. William Wells bill at proxftl.UUCP
Fri Sep 30 01:29:23 AEST 1988


In article <1851 at loral.UUCP> jlh at 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



More information about the Comp.lang.c mailing list