161 S:Declaration in for statement. 避免在for循环中定义变量:
void STATIC_161(void)
{
UINT32_t x, y=0;
for(unsigned x(0);x <3;x++) /* not compliant */
{
y++;
}
}
162 S:Method defined within class declaration. 除了成员函数,不要在类申明中定义函数。
163 S:Function starts with upper case character. 建议与175S一起取消。
164 S:Use of void * pointer. 避免使用void类型指针:
static void proc(void *ptr) { ; } /* not compliant */
void * a_proc ( void ) /* not compliant */
{
return NULL;
}
void static_164 ( void )
{
void * p = a_proc(); /* not compliant */
proc(p);
}
165 S:Nested class declaration. 避免嵌套使用类:
class one {
public:
long along;
class nested
{
public:
short s;
nested(){;}
};
one()
{
nested anest;
}
};
166 S:Class declared in function body.避免在函数体内定义类:
class one {
public:
long l;
one(){;}
void aproc()
{
class inproc1
{
public:
short s;
inproc1(){;}
};
}
};
167 S:Class variable declared in class definition. 建议不要直接在结构体或者类定义后申明变量,使用typedef是更好的做法:
class one {
public:
long a;
one(){;}
} aone, *paone;
168 S:Call by value parameter not const. 值类型的函数参数传递建议使用const修饰:
static void aproc( SINT32_t iv_param) {;} /* not compliant */
static void bproc(const SINT32_t ic_param) {;}
static SINT32_t static_168 (void)
{
SINT32_t loc_var = 0;
aproc(loc_var);
bproc(loc_var);
}
169 S:Use of forward reference of class member. 注意在类中变量的定义要在使用之前:
class ok
{ public:
INT32_t x;
ok(void) { x = 1; }
};
class notok
{ public:
notok() { d = 91; /* not compliant */ }
INT32_t d;
};
170 S:Procedure call has no prototype and no defn. 被调用的函数缺少申明或者定义。
171 S:已取消
172 S:Variable declared multiply.变量重复定义:
UCHAR_t ddd;
UCHAR_t ddd; /* not compliant */
UCHAR_t ddd = 0U;
static void static_172( void )
{
;
}
173 S:Class member starts with upper case character.类的函数应当以小写字符开头命名(构造函数除外):
class one {public:
void Upper2_out(); /* not compliant */
};
174 S:Class member starts with lower case character.类的成员函数应当以大写字符开头命名:
class one {
public:
INT32_t x;
void notokproc1 () /* not compliant */
{
}
};
175 S:Function starts with lower case character. 建议与163S一起取消。
176 S:Non standard escape sequence in source. 避免出现转义字符:
void static_176 (void)
{
char c = 'b';
switch(c)
{
case '\m': /* not compliant */
break;
default:
break;
}
}
177 S:Identifier not declared on new line. 建议每个变量都单起一行定义:
INT32_t okvar, notok2; /* not compliant */
void static_177(void)
{
okvar = 0;
notok2 = 2;
}
178 S:Declaration statement not on new line.同177S:
INT32_t * oka;
INT32_t b; INT32_t *notoka; /* not compliant */
void proc( INT32_t * s, INT32_t *ok); /* compliant */
struct tag0 { INT32_t * w; INT32_t *notokq;} astr; /* not compliant */
static void static_178(void)
{
oka = 0;
}
179 S:Extern not at start of header file. extern类型变量应当声明在源文件开头处:
#include "c_standards.h"
#include "Static_179.h"
/********************************************************
* Standard 179 S : Extern not at start of header file.
********************************************************/
static void static_179(void)
{
;
}
/*
* Copyright (c) 2001 Liverpool Data Research Associates
*
*
*/
Static_179.h
INT32_t var;
extern INT32_t ex; /* not compliant */
180 S:No space between * or & and name in declaration. * 或者 &与变量名之间应当有空格。