MISRA C:2012 Dir 4.9
A function should be used in preference to a function-like macro where they are interchangeable
Description
Directive Definition
A function should be used in preference to a function-like macro where they are interchangeable.
Rationale
When feasible, use functions instead of macros. Functions perform argument type-checking and evaluate their arguments once, avoiding problems with potential multiple side effects.
Polyspace Implementation
Polyspace® reports violations of this rule for all function-like macro definitions.
As an exception, Polyspace does not report a violation of this rule if you use function like
macros for _Generic
selection.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Code design |
Category: Advisory |
AGC Category: Advisory |