您的位置:首页 > 其它

vc下proc开发环境与pclint的配置-pclint相关

2014-08-11 15:09 417 查看
另外,针对一些常见的警告或错误提示,做一个说明:

1、error 530: (Warning -- Symbol 'tmp' (line 643) not initialized)

这个很容易,根据提示说明,是变量定义后没有初始化,在变量定义时初始化就可以解决;

2、memcpy(&PriceInfo.sReportCode, aData, i);

svr_refhq.pc(377): error 545: (Warning -- Suspicious use of &)

由于系统函数memcpy的参数是指针,所以实际是要将sReportCode的地址作为参数传入,但目前的写法存在一些问题:

第一,这里的写法是取得PriceInfo的地址还是PriceInfo.sReportCode的地址?

第二,sReportCode本身是字符串,即字符数组,不带下标的时候就是表示的首字符,也即指针地址,所以再用 & 来取地址会取得指针的指针。

3、#define COLUMNS_MAX_LEN 1024

D:\mywork\O32\Sources\Src\svr_instruction\utils.h(14): error 760: (Info -- Redundant macro 'COLUMNS_MAX_LEN' defined identically at line 42, file d:\mywork\O32\Sources\Src\public\sstruction.h)

d:\mywork\O32\Sources\Src\public\sstruction.h(42): error 830: (Info -- Location cited in prior message)

这是由于在utils.h和sstruction.h里都定义了同一个名字COLUMNS_MAX_LEN的宏,根据提示redundant很容易知道,只要去掉utils.h里的定义就可以了。

4、 memset(&sSQL,0,sizeof(sSQL));

D:\mywork\O32\Sources\Src\svr_instruction\svr_instrcancel.pc(52): error 545: (Warning -- Suspicious use of &)

这个警告和第3点的类似,正确的做法:

sSQL char[1024];

初始化:sSQL[0]='0\';

这样初始化可以大大提高性能,对于大字符串尽量少用memset的方式,即使要用,也应该是:

memset(sSQL,0,sizeof(sSQL));

5、 iRet = CallServiceA("CallASARService", Sendbuff, GErrorMessage);

D:\mywork\O32\Sources\Src\svr_instruction\svr_instrcancel.pc(320): error 718: (Info -- Symbol 'CallServiceA' undeclared, assumed to return int)

这个错误是因为CallServiceA()只有spub.c里的实现,没有在spub.h里声明,不符合C语言的标准用法,通过在spub.h里增加声明解决。

6、 if (iUnApprove > 0 )

D:\mywork\O32\Sources\Src\svr_instruction\svr_instrcancel.pc(379): error 774: (Info -- Boolean within 'if' always evaluates to False [Reference: file D:\mywork\O32\Sources\Src\svr_instruction\svr_instrcancel.pc: lines 43, 379])

D:\mywork\O32\Sources\Src\svr_instruction\svr_instrcancel.pc(43): error 831: (Info -- Reference cited in prior message)

D:\mywork\O32\Sources\Src\svr_instruction\svr_instrcancel.pc(379): error 831: (Info -- Reference cited in prior message)

这一系列的错误是因为iUnApprove初始化时赋值为0,后面只有select语句里对该变量赋值,当用PCLINT对 .pc文件进行检查时,pclint无法识别该语句,因此会以为没有对iUnApprove赋值,始终为false。

需要改变一下做法,改为对 .c文件做检查。具体做法,在每个要检查的.pc文件的‘设置’中,在proc 命令行下面增加如下的命令行:

c:\pclint\lint-nt -u c:\pclint\lnt\std.lnt c:\pclint\lnt\env-vc6.lnt "$(InputDir)\$(InputName).c"

这样设置后,就不再需要用 工具里设置的pc lint来检查了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: