pclint测试c或c实例.docVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
PC-lint测试C/C++实例 实例1:test.cpp 1 #include string.h 2 class X 3 { 4 int *p; 5 public: 6 X() 7 { p = new int[20]; } 8 void init() 9 { memset( p, 20, a ); } 10 ~X() 11 { delete p; } 12 }; 编译这个文件,VC6.0产生0 errors 0 warnings, 而lint程序产生了如下8条警告信息,有些还是很有用处的提示。 PC-lint 告警信息: test.cpp(12): error 783: (Info -- Line does not end with new-line) test.cpp(7): error 1732: (Info -- new in constructor for class X which has no assignment operator) test.cpp(7): error 1733: (Info -- new in constructor for class X which has no copy constructor) { memset( p, 20, a ); } test.cpp(9): error 669: (Warning -- Possible data overrun for function memset(void *, int, unsigned int), argument 3 (size=97) exceeds argument 1 (size=80) [Reference: test.cpp: lines 7, 9]) test.cpp(7): error 831: (Info -- Reference cited in prior message) test.cpp(9): error 831: (Info -- Reference cited in prior message) { delete p; } test.cpp(11): error 424: (Warning -- Inappropriate deallocation (delete) for new[] data) --- Wrap-up for Module: test.cpp test.cpp(2): error 753: (Info -- local class X (line 2, file test.cpp) not referenced) error 900: (Note -- Successful completion,8 messages produced) 根据错误提示修改后的程序如下: #include string.h class X /*lint -e753 */ //只声明实现类X,没有写main()应用类x,故可以屏蔽。 { int *p; public: X() //构造函数 { p = NULL; } X (const X x) //拷贝构造函数 { p = new int[20]; memcpy(p, x.p, 20*sizeof(int)); } X operator= (const X x) //赋值操作符 { if (this == x) //检查自赋值 { return *this; } int *temp = new int[20]; memcpy(temp, x.p, 20*sizeof(int)); //复制指针指向内容 delete []p; //删除原有指针(将删除操作符放在后面,避免X=X特殊情况下,内容的丢失) p=temp; //建立新指向 return *this; } void init() { if (NULL == p) return; // 判断指针是否为空 memset( p, a, 20*sizeof(int)); } ~X() { delete []p; } }; test.cpp(12): error 783: (Info -- Line

文档评论(0)

187****5045 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档