您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > PCLint使用指南
更多参考资料下载:讲座LecturesonPCLint/FlexeLint作者:刘飞祥Email:openlek@live.cn二○○八年十月更多参考资料下载:版权声明技术是人类共同的财富,同时本文选取的数值计算程序库都来源开源社区,没有秘密可言。再说开源的初衷就是为了共享、传播知识。因此,作者愿意公开本电子文档,并乐于与大家分享我的学习成果。版权声明如下:(1)读者可以任意拷贝、修改本书的内容,但不可以篡改作者及所属单位。(2)未经作者许可,不得公开出版或大量印发以获取利益,以传播知识为目的电子拷贝除外。(3)请遵守其他法律规定,以免发生纠纷。欢迎读者对本文档提出批评建议,信息反馈请联系Email:openlek@live.cn。CopyrightCopyright2008Authors:LiuFeixiangEmail:openlek@live.cnThisLICENSEpageispartofAnOverviewonNumericalAnalysisSoftware,YoucannotremovetheLicensepage.Permissionisgrantedtocopy,distributeand/ormodifythisdocument,providedthetextofthisNOTICEisretained,anoticethatthecodewasmodifiedisincludedwiththeaboveCOPYRIGHTNOTICEandwiththeCOPYRIGHTNOTICEintheLICENSEfile,andthattheLICENSEfileisdistributedwiththemodifiedcode.Specifically,Iwanttomakesurethatyouhavetherighttosharecopies.LICENSORMAKESNOREPRESENTATIONSORWARRANTIES,EXPRESSORIMPLIED.MAKESNOREPRESENTATIONSORWARRANTIESOFMERCHANTABILITYORFITNESSFORANYPARTICULARPURPOSEORTHATTHEUSEOFTHELICENSEDSOFTWARECOMPONENTSORDOCUMENTATIONWILLNOTINFRINGEANYPATENTS,COPYRIGHTS,TRADEMARKSOROTHERRIGHTS.更多参考资料下载:介绍.............................................................................41.1介绍.........................................................................................................41.2实例.........................................................................................................41.3参考书目.................................................................................................7第二讲PCLint安装与配置.................................................................................82.1安装..........................................................................................................82.2配置..........................................................................................................92.3测试........................................................................................................16第三讲PCLint高级话题...................................................................................183.1集成到IDE............................................................................................183.2MAKEFILE...........................................................................................18更多参考资料下载:介绍1.1介绍该软件在PC市场(Windows,MS-DOS,OS/2)就叫做PCLint,对于其他平台,则称作FlexeLint。这就是PCLint/FlexeLint的来历。本文只考虑PCLint/FlexeLint在Windows下的使用,因此下面使用的PCLint就是指PCLint/FlexeLint。PCLint/FlexeLint是一款代码静态分析工具,它的作用就是查找C/C++程序的错误与缺陷(bugs),分析代码存在的潜在问题,比编译器更要严格。其中C语言依据的标准是K&R[1]andANSI——C89[2],包括了C’99[3]标准,但支持C’99[3]的所有特性;C++依据的标准是ANSI/ISO标准[4]。[5]GuidelinesfortheUseoftheCLanguageinVehicleBasedSoftware(MISRA),TheMotorIndustryResearchAssociation,April1998,Warwickshire,UK,[6]Meyers,Scott,EffectiveC++,Addison-Wesley,ReadingMA,1992[7]Cargill,Tom,C++Gotchas,presentedatC++World,November1992.1.2实例char*report(shortm,shortn,char*p){intresult;char*temp;longnm;inti,k,kk;charname[11]=JoeJakeson;nm=n*m;temp=p==?null:p;for(i=0;im;i++){k++;kk=i;}if(k==1)result=nm;elseif(kk0)result=1;elseif(kk0)result=-1;if(m==result)returntemp;elsereturnname;}大多数编译器都把它当作一个有效正常的C/C++程序,VC6.0下只报告一个错误:函数返回自动变量。然而,用PCLint检查时,就会报告一大堆错误和问题。下面给出PCLint的报告输出,详细内容解剖会在后文给出,在此先跳过。---Module:demo.c_char*report(shortm,shortn,char*p)demo.c(1):Note970:Useofmodifierortype'char'outsideofatypedef更多参考资料下载:[MISRARule13]demo.c(1):Note971:Useof'char'without'signed'or'unsigned'[MISRARule14]demo.c(1):Note970:Useofmodifierortype'short'outsideofatypedef[MISRARule13]demo.c(1):Note970:Useofmodifierortype'short'outsideofatypedef[MISRARule13]demo.c(1):Note970:Useofmodifierortype'char'outsideofatypedef[MISRARule13]demo.c(1):Note971:Useof'char'without'signed'or'unsigned'[MISRARule14]_{demo.c(2):Note957:Function'report'definedwithoutaprototypeinscope[MISRARule71]_intresult;demo.c(3):Note970:Useofmodifierortype'int'outsideofatypedef[MISRARule13]_char*temp;demo.c(4):Note970:Useofmodifierortype'char'outsideofatypedef[MISRARule13]demo.c(4):Note971:Useof'char'without'signed'or'unsigned'[MISRARule14]_longnm;demo.c(5):Note970:Useofmodifierortype'long'outsideofatypedef[MISRARule13]_inti,k,kk;demo.c(6):Note970:Useofmodifierortype'int'outsideofatypedef[MISRARule13]_charname[11]=JoeJakeson;demo.c(7):Note970:Useofmodifierortype'char'outsideofatypedef[MISRARule13]demo.c(7):Note971:Useof'char'without'signed'or'unsigned'[MISRARule14]demo.c(7):Info784:Nulcharactertruncatedfromstring_temp=p==?null:p;demo.c(10):Info779:Stringconstantincomparisonoperator'=='demo.c(10):Warning605:Increaseinpointercapability(assignment)--更多参考资料下载:{k++;kk=i;}demo.c(12):Warning530:Symbol'k'(line6)notinitialized[MISRARule30]demo.c(6):Info830:Locationcitedinpriormessage_if(k==1)result=nm;demo.c(13):Note960:ViolatesMISRARequiredRule59,leftbraceexpectedforif,else,for,doandwhile_elseif(kk0)result=1;demo.c(1
本文标题:PCLint使用指南
链接地址:https://www.777doc.com/doc-5198922 .html