这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 今天看了PC-lint的东西,想再受一点打击,随便写写!

共1条 1/1 1 跳转至

今天看了PC-lint的东西,想再受一点打击,随便写写!

菜鸟
2003-08-23 22:52:04     打赏
很久以前使用过PC-lint,整个代码被发现600多处waring,郁闷! 今天试了试8.0版本的,随便写一点,[color=#DC143C]好的工具是成功的一个关键![/color] PC-Lint C/C++静态分析工具 -------------------------------------------------- 1.支持的C/C++语言标准 C:K&R/ANSI C++:ANSI/ISO -------------------------------------------------- 2.PC-Lint介绍 PC-Lint的作用大家都应该有所耳闻!我在这里应用PC-Lint的Help问当中的一句话: PC-lint/FlexeLint finds quirks, idiosyncrasies, glitches and bugs in C and C++ programs. 总值一句话,PC-Lint可以做得比你所用的Compiler更严格的检查! 下面是Help里面的例子: 1: 2: char *report( short m, short n, char *p ) 3: { 4: int result; 5: char *temp; 6: long nm; 7: int i, k, kk; 8: char name[11] = "Joe Jakeson"; 9: 10: nm = n * m; 11: temp = p == "" ? "null" : p; 12: for( i = 0; i < m; i++ ) 13: { k++; kk = i; } 14: if( k == 1 ) result = nm; 15: else if( kk > 0 ) result = 1; 16: else if( kk < 0 ) result = -1; 17: if( m == result ) return temp; 18: else return name; 19: } 我曾自己分析过这断程序,找出的Waring也不过3处!然后一看解释部分,结论是我的编程功夫还需要再好好的学!汗ing... 大家可以试一下用PC-Lint来分析!希望不要的出我那样的结论! PC-Lint的C++检查是主要针对有可能忽略的类型检查和大型编程的多模块冲突。(鉴于小弟对C++不是很熟悉,所以...) -------------------------------------------------- 3 安装 过程(略)......(不会有人拿鸡蛋丢我吧?) -------------------------------------------------- 4 设置 在开始菜单中运行PC-lint/Configuration Wizard! 在设置的过程中,需要选择PC-lint的配置文件STD.lnt或者其他的STD_X.lnt等的,还需要设置头文件目录等信息! ------------------------------------------------- 5 例子 D:\Lint>lin filea.cpp fileb.cpp(这是需要你键入的,以下的都是输出的了) D:\Lint>"D:\Lint\Lint-nt" +v -i"D:\Lint" std.lnt -os(_LINT.TMP) filea.cpp f ileb.cpp PC-lint for C/C++ (NT) Ver. 8.00h, Copyright Gimpel Software 1985-2002 --- Module: filea.cpp --- Module: fileb.cpp D:\Lint>type _LINT.TMP | more --- Module: filea.cpp --- Module: fileb.cpp _ }; fileb.cpp 5 Warning 631: tag 'X' defined differently at line 4, file filea.cpp --- Global Wrap-up Warning 1527: static member 'X::a' (line 6, file filea.cpp) not defined --- output placed in _LINT.TMP D:\Lint> ####################################### 第二个例子 D:\Lint>lin -itest \test\test1.lnt(这是需要你键入的,以下的都是输出的了) D:\Lint>"D:\Lint\Lint-nt" +v -i"D:\Lint" std.lnt -os(_LINT.TMP) -itest \tes t\test1.lnt PC-lint for C/C++ (NT) Ver. 8.00h, Copyright Gimpel Software 1985-2002 --- Module: test\module1.cpp --- Module: test\module2.c D:\Lint>type _LINT.TMP | more --- Module: test\module1.cpp --- Wrap-up for Module: test\module1.cpp Info 753: local class 'X' (line 7, file test\module1.cpp) not referenced test\module1.cpp 7 Info 830: Location cited in prior message --- Module: test\module2.c _ { test\module2.c 3 Error 18: Symbol 'alpha(int)' redeclared (Arg. no. 1: signed/unsigned,precision) conflicts with line 4, file test\module1.cpp test\module1.cpp 4 Info 830: Location cited in prior message { test\module2.c 3 Warning 516: 'Symbol alpha(unsigned long)' has arg. type conflict (arg. no. 1 -- unsigned long vs. int) with line 4, file test\module1.cpp test\module1.cpp 4 Info 830: Location cited in prior message return (unsigned) l >> 16; test\module2.c 4 Warning 572: Excessive shift value (precision 16 shifted right by 16) --- Global Wrap-up Info 1714: Member function 'X::f(int)' (line 9, file test\module1.cpp) not referenced test\module1.cpp 9 Info 830: Location cited in prior message --- output placed in _LINT.TMP D:\Lint 未完,待续......



关键词: 今天     看了     PC-lint     东西     想再     一点     打击    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]