前言
一、下载
二、揭开PC-Lint9的神秘面纱
D:\PC-Lint9>lint-nt -v PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008
三、升级到最新版本
D:\PC-Lint9>update.bat D:\PC-Lint9>PATCH.EXE LP9-A-B.RTP D:\PC-Lint9>PATCH.EXE LP9-B-C.RTP D:\PC-Lint9>PATCH.EXE LP9-C-D.RTP D:\PC-Lint9>PATCH.EXE LP9-D-E.RTP D:\PC-Lint9>PATCH.EXE LP9-E-F.RTP D:\PC-Lint9> D:\PC-Lint9> D:\PC-Lint9>lint-nt -v PC-lint for C/C++ (NT) Vers. 9.00f, Copyright Gimpel Software 1985-2010
四、在线试用
五、若干例子
-i"D:\PC-Lint9.0\lnt" co-msc90.lnt -i"C:\Program Files\Microsoft Visual Studio 9.0\VC\include"
#include <string.h> class X { int *p; public: X() { p = new int[20]; } void init() { memset( p, 20, 'a' ); } ~X() { delete p; } };
D:\Projects\Lab\PC-lint9-test\tests>lint-nt std.lnt simple.cpp PC-lint for C/C++ (NT) Vers. 9.00f, Copyright Gimpel Software 1985-2010 --- Module: simple.cpp (C++) _ { p = new int[20]; } simple.cpp(8) : Info 1732: new in constructor for class 'X' which has no assignment operator simple.cpp(8) : Info 1733: new in constructor for class 'X' which has no copy constructor _ { memset( p, 20, 'a' ); } simple.cpp(10) : Warning 669: Possible data overrun for function 'memset(void *, int, unsigned int)', argument 3 (size=97) exceeds argument 1 (size=80) [Reference: file simple.cpp: lines 8, 10] simple.cpp(8) : Info 831: Reference cited in prior message simple.cpp(10) : Info 831: Reference cited in prior message _ { delete p; } simple.cpp(12) : Warning 424: Inappropriate deallocation (delete) for 'new[]' data --- Wrap-up for Module: simple.cpp Info 753: local class 'X' (line 3, file simple.cpp) not referenced simple.cpp(3) : Info 830: Location cited in prior message --- Global Wrap-up Info 1714: Member function 'X::init(void)' (line 9, file simple.cpp) not referenced simple.cpp(9) : Info 830: Location cited in prior message
D:\Projects\Lab\PC-lint9-test\tests\multimodule>lint-nt std.lnt files.lnt PC-lint for C/C++ (NT) Vers. 9.00f, Copyright Gimpel Software 1985-2010 --- Module: a.cpp (C++) --- Module: b.cpp (C++) _ int b = a; b.cpp(3) : Warning 1544: Value of variable 'a' (line 4, file a.cpp) indeterminate (order of initialization) a.cpp(4) : Info 830: Location cited in prior message --- Global Wrap-up
D:\Projects\Lab\PC-lint9-test\tests>lint-nt multi-threading.cpp PC-lint for C/C++ (NT) Vers. 8.00w, Copyright Gimpel Software 1985-2007 --- Module: multi-threading.cpp (C++) _ //lint -sem( reader, thread ) multi-threading.cpp 6 Warning 425: 'unrecognized name' in processing semantic 'thread' at token 'thread' _ //lint -sem( Lock::Lock, thread_lock ) multi-threading.cpp 7 Warning 425: 'unrecognized name' in processing semantic 'thread_lock' at token 'thread_lock' _ //lint -sem( Lock::~Lock, thread_unlock ) multi-threading.cpp 8 Warning 425: 'unrecognized name' in processing semantic 'thread_unlock' at token 'thread_unlock' D:\Projects\Lab\PC-lint9-test\tests> D:\Projects\Lab\PC-lint9-test\tests> D:\Projects\Lab\PC-lint9-test\tests>set path=D:\Tools\CMD\Lint\SmartLint\PC-Lint9.0 D:\Projects\Lab\PC-lint9-test\tests>lint-nt multi-threading.cpp PC-lint for C/C++ (NT) Vers. 9.00f, Copyright Gimpel Software 1985-2010 --- Module: multi-threading.cpp (C++) --- Thread messages: Warning 457: Function 'h(void)' of thread 'main(void)' has an unprotected write access to variable 'x' which is used by function 'h(void)' of thread 'reader(void)' Warning 458: Function 'h(void)' of thread 'main(void)' has an unprotected read access to variable 'y' which is modified by function 'g(void)' of thread 'reader(void)'
六、辅助工具
七、PC-Lint9.0新增功能
6、“宏净化(Macro Scavenging)”。这个功能想必是为了解决PC-Lint与GCC不同版本配合中需要大量人工配置的尴尬局面吧。听起来不错的一个解决方案,具有较强的通用性。
7、新加入的“-sem”语法:成员方法的初始化/回收职能标识、inout类参数标识、多线程分析辅助标识…… 这一系列补充标识都是非常有实用价值的,尤其是前两项,解决了C++工程维护中扩充成员时经常碰到的忘记写配套的初始化或释放处理的顽疾。