常量后缀由应由大写字母组成
11.8 ID_literal_confusingSuffix
小写字母“l”极易与数字“1”混淆,为了提高可读性,常量后缀均应由大写字母组成。
示例:
long long a = 100ll; // Non-compliant, may be misread as 10011
long double b = 100.l; // Non-compliant, may be misread as 100.1
应改为:
long long a = 100LL; // Compliant
long double b = 100.L; // Compliant
后缀大小写混用的情况会使人更加困惑:
long long c = 100lL; // Non-compliant, very bad
unsigned long long d = 100lLU; // Non-compliant, very bad
其中,小写的 l 和大写的 L 混在了一起,应改为:
long long c = 100LL; // Compliant
unsigned long long d = 100LLU; // Compliant
配置
allSuffixCharMustBeUpperCase: 要求后缀中所有字符均为大写,或只要求小写字符“l”不得用于后缀
参考
C++ Core Guidelines NL.19
MISRA C 2012 7.3
MISRA C++ 2008 2-13-4