MISRA C:2023 Dir 4.5
Identifiers in the same name space with overlapping visibility should be typographically unambiguous
自 R2024a 起
描述
指令定义
Identifiers in the same name space with overlapping visibility should be typographically unambiguous 1 .
理由
“明确易辨”的含义取决于编写源代码时所用的字母表和语言。当您使用在排字上很接近的标识符时,您可能会产生混淆。
对于英语单词中使用的拉丁字母,至少要避免标识符之间只有以下区别:
小写字母与其对应的大写字母互换。
是否存在下划线字符。
字母
O
与数字0
互换。字母
I
与数字1
互换。字母
I
与字母l
互换。字母
S
与数字5
互换。字母
Z
与数字2
互换。字母
n
与字母h
互换。字母
B
与数字8
互换。字母
rn
与字母m
互换。
Polyspace 实现
检查项会标记在同一作用域内且仅存在上述字符差异的标识符。Polyspace® 会忽略以 do
、for
、switch
和 while
开头的宏中定义的标识符。
如果两个标识符的作用域不同,它们的使用就不会产生歧义。对于作用域不同的标识符,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.