201 S:Use of numeric literal in expression. 该条规则建议使用宏或者枚举代替具体的数字,以提高代码的可维护性。
202 S:Class data is not explicitly private. 建议类中的成员变量为私有。
203 S:Cast on a constant value. 避免对常量进行强制类型转换:
const INT16_t con = 19;
const INT16_t * pcon;
static void static_203(void)
{
INT16_t x;
INT16_t *p;
x = (INT16_t)con; /* not compliant if modifier = 0 */
p = (INT16_t *)pcon; /* not compliant */
}
204 S:continue or goto not defined to rubbish. 避免使用goto和continue语句。
void static_184(struct tag * astr,
INT32_t b [] /* not compliant */ )
{
astr ->f = 2; /* not compliant */
}
205 S:Use of multiple inheritance. 避免在类中使用复杂的多重继承。
206 S:Class initialiser out of order.类成员初始化的顺序需要与申明时候的顺序一致。
207 S:Use of old style /* comments in C++. 建议C++注释中使用双斜杠。
208 S:Private data name needs trailing underscore. 类的私有变量建议以下划线结尾以做区分:
class MyClass
{
private:
UINT32_t m_ok_item_;
UINT32_t m_not_ok_item; /* not compliant */
protected:
public:
};
209 S:Preprocessor command indented. 宏定义顶头写,不建议有缩进:
#ifndef XXX
/* not compliant */
#define XXX
#endif
210 S:Macro name is not upper case. 建议宏定义变量名大写。
211 S:Overloaded &&, || or comma. 请不要重定义&&, || 或者 comma。
212 S:Use of friend function in class.谨慎的使用友元类,以免在类继承或者重新设计接口是带来隐患。
213 S:Use of friend class.同212S。
214 S:Member not declared virtual.建议基类中函数申明为virtual类型。
215 S:Struct or class called by value. 避免直接使用结构体作为函数的入参,或者作为函数的返回值,这样会消耗额外的内存空间,使用指针是更合理的方式。
216 S:Pointer name does not have required suffix. 建议变量的名称以变量的类型为后缀,增加代码的可读性:
static void static_216( void )
{
UCHAR_t * pointer; /* not compliant */
UCHAR_t * ptr; /* ok as allowed suffix is ptr */
UCHAR_t * aptr; /* ok as allowed suffix is ptr */
/***/
}
217 S:Names only differ by case. 避免出现两个变量仅仅是某些字符大小写不同:
INT32_t Foobar;
INT32_t foobar; /* not compliant */
INT32_t fOobar; /* not compliant */
void aproc(CHAR_t aC2; INT32_t FooBar) {;} /* not compliant */
void static_217 (void)
{
struct tag{ CHAR_t aC1, INT32_t FooBar;} local; /* Ok as different scope */
}
218 S:Name is used in standard libraries.命名时避免与C/C++标准库中的名称重复。
219 S:User name starts with underscore. 避免以下划线开始命名变量。
220 S:No prefix for global type. 建议全局变量名称后缀该变量的类型以增加可读性。