Re: PATCH, RFC: Version 3 of 2.6 Codingstyle

From: Jamie Lokier
Date: Sun Feb 15 2004 - 05:11:06 EST


Dmitry Torokhov wrote:
> On Friday 13 February 2004 08:44 pm, Michael Frank wrote:
> > -expression in parenthesis. Note that this does not eliminate all side effects.
> > +4) forgetting about side effects: macros defining expressions must enclose each
> > +parameter and the expression in parentheses.
> >
> > #define CONSTEXP (CONSTANT | 3)
> > #define MACWEXP(a,b) ((a) + (b))
> >
>
> The statements above are incorrect.
>
> Parentheses will never eliminate a side effect, macros do not have a
> "side effect problem". Functions and macros both can have side effects
> and sometimes side effect is a desired outcome.

Macros do have a side effect problem, but it is not something which is
fixed by parentheses. The problem comes when the argument of the
macro is repeated more than once, or zero times, in the macro body.
Then any side effect that the caller was expecting takes place the
wrong number of times.

A subtler version occurs when the caller expects the side effect in an
argument to occur before the action of the macro, but the macro
doesn't expand the argument in that order.

See "Duplication of Side Effects" in the GNU CPP manual.

-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/