MISRA C++:2023 Rule 11.3.1
描述
Variables of array type should not be declared. 1
理由
C 样式数组对象的大小信息并非始终都会保留。使用像 std::array 这样容器来保留大小信息会更安全。
作为例外,如果立即用字符串字面值初始化数组,则声明 const char 数组并不违规。
Polyspace 实现
如果您的代码包含 C 样式的数组,则 Polyspace® 会报告违反此规则。当向函数传递传统的 C 样式数组时,Polyspace 不会报告违反此规则,因为数组在作为参量传递给函数时会衰减为指针。
故障排除
如果您预期会出现违规,而 Polyspace 未报告该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:声明符 |
| 类别:建议 |
PQL 名称:std.misra_cpp_2023.R11_3_1 |
版本历史记录
在 R2024b 中推出
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.