MISRA C++:2023 Rule 19.3.4
Parentheses shall be used to ensure macro arguments are expanded appropriately
Since R2024b
Description
Rule Definition
Parentheses shall be used to ensure macro arguments are expanded appropriately.
Rationale
Macro expansion results in textual replacement where the preprocessor replaces a code snipped directly into your code before compilation. This direct text replacement can result in unexpected behavior if the arguments are expressions due to operator precedence.
If you are not using a macro parameter as an expression, then the parentheses are not necessary because no operators are involved in the macro.
Polyspace Implementation
Polyspace® reports this rule violation whenever a macro parameter argument is an expression that contains an operator or operand and is not enclosed in parentheses. Violations are not reported if you use an unparenthesized array element as a macro parameters.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Preprocessing Directives |
Category: Required |
Version History
Introduced in R2024b