MISRA C:2023 Dir 4.9
A function should be used in preference to a function-like macro where they are interchangeable
自 R2024a 起
描述
指令定义
A function should be used in preference to a function-like macro where they are interchangeable.
理由
如果可行,请使用函数而不是宏。函数会执行参量类型检查并评估其参量一次,从而避免可能产生多重副作用的问题。
Polyspace 实现
Polyspace® 会报告所有类似函数的宏定义违反此规则的情形。
作为例外,如果您使用类似函数的宏进行 _Generic 选择,则 Polyspace 不会报告违反此规则的情形。
故障排除
如果您预计存在违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:代码设计 |
| 类别:建议 |
| AGC 类别:建议 |
版本历史记录
在 R2024a 中推出