MISRA C:2012 Rule 8.13
A pointer should point to a const-qualified type whenever possible
描述
规则定义
A pointer should point to a const-qualified type whenever possible 1 .
理由
此规则可确保您不会无意中使用指针来修改对象。
Polyspace 实现
如果指针未修改所引用的对象,规则检查项会标记指向非 const
函数参数的指针。假设指针并非用于修改对象,因此必须指向 const
- 合格类型。如果非 const
指针所指向的数据被指针的副本修改,则 Polyspace® 不会设置标记。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
组:声明和定义 |
类别:建议 |
AGC 类别:建议 |
版本历史记录
在 R2014b 中推出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.