Re: PATCH, RFC: Version 3 of 2.6 Codingstyle

From: Dmitry Torokhov
Date: Fri Feb 13 2004 - 22:45:06 EST


On Friday 13 February 2004 08:44 pm, Michael Frank wrote:
>
> -4) forgetting about sideeffects. Macros defining expressions must enclose the
> -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.

Parentheses will only prevent surprises when argument expansion takes
place:

#define times_2(a) (a * 2)
b = macro(a + 2);

will be expanded to:

b = (a + 2 * 2);

which is obviously not what programmer had in mind.

--
Dmitry
-
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/