主要内容

MISRA C++:2008 Rule 2-13-4

Literal suffixes shall be upper case

描述

规则定义

Literal suffixes shall be upper case. 1

理由

字面值常量可以以字母 l(读作“el”)结尾。强制字面值后缀使用大写可消除字母 l 与数字 1 之间可能产生的混淆。

为保持一致性,其他后缀也应使用大写常量,例如 U(无符号)和 F(浮点)。

故障排除

如果您预期会出现违规,而 Polyspace® 未报告该违规,请参阅诊断为何编码规范违规未按预期显示

示例

全部展开

const int a = 0l; //Noncompliant
const int b = 0L; //Compliant

在此示例中,ab 被赋值了同一个字面值常量。然而,从表面上看,可能会误以为 a 被赋值为 01(八进制的 1)。

检查信息

组:词法规范
类别:必需

版本历史记录

在 R2013b 中推出


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.