MISRA C:2023 Rule 8.13
描述
规则定义
A pointer should point to a const-qualified type whenever possible 1 .
理由
此规则可确保您不会无意中使用指针来修改对象。
Polyspace 实现
该规则检查项会将指向非 const 函数参数的指针标记出来,前提是该指针未修改其指向的对象。假设条件是指针的用途不是用来修改该对象,因此它必须指向一个 const 限定类型。如果通过指针的副本修改了非 const 指针所指向的数据,则 Polyspace® 不会进行标记。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:声明和定义 |
| 类别:建议 |
| AGC 类别:建议 |
版本历史记录
在 R2024a 中推出
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.