MISRA C:2012 Rule 23.1
Description
Rule Definition
A generic selection should only be expanded from a macro.
This rule comes from MISRA C™: 2012 Amendment 3.
Rationale
Generic selections allow you to query the type of its argument and then select different actions for different types. By selecting actions depending on the type of the argument, your code can accommodate generic functions. If you use generic selection directly in your code, then the type of its operand is already known and the generic selection is no longer useful.
The best practice is to implement generic selection in a function-like macro and perform selection based on the type of its argument.
Polyspace Implementation
This rule checker reports a violation if either of these conditions are met:
A generic selection is not expanded from macro.
The selector of a generic selection is not an argument of the expanded macro.
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: Generic Selections |
Category: Advisory |
AGC Category: Advisory |
Version History
Introduced in R2024a