Re: [RFC PATCH 12/13] blk-mq.h: Fix parentheses around macro parameter use

From: Mathieu Desnoyers
Date: Mon May 08 2023 - 10:29:02 EST


I've attempted to capture the resulting rules based on our discussion to add this to
coding-style.rst. Please let me know if anything is wrong:

(to be added in section 12) Macros, Enums and RTL)

Always use parentheses around macro arguments, except when:

- they are used as a full expression:
- as an initializer,
- as an expression statement,
- as the controlling expression of a selection statement (``if`` or ``switch``),
- as the controlling expression of a ``while`` or ``do`` statement,
- as any of the expressions of a ``for`` statement,
- as the expression in a return statement,
- they are used as expression within an array subscript operator "[]",
- they are used as arguments to functions or other macros,
- there is some syntax reason why adding the parentheses would not work.

(note: I'm unsure about requiring or not the parentheses around initializers.
Based on C11 section "6.8 Statement and blocks", initializers that are not part of
a compound literal are full expressions, which makes the extra parentheses useless.)

Thanks,

Mathieu

--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com