zoukankan      html  css  js  c++  java
  • pclint入门

    1.   安装

    将压缩包比如pclint8.zip拷贝到c:\,解压后重命名目录为c:\pclint

     

    版本

    Q:如何查看版本?

    A:readme.txt

    PC-lint for C/C++ Version 8.00e

    2.   开始使用

    2.1. 不用任何配置,直接使用

    2.1.1.    准备待被检查的文件:

    先在E:\建一个文件:main.cpp,内容为:

    void main()

    {  

    }

     

    2.1.2.    最简单的用法

    在命令行下输入:D:\>C:\PCLint\Lint-nt E:\main.cpp

    C:\PCLint>C:\PCLint\Lint-nt E:\main.cpp

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   E:\main.cpp

    _

    }

     

    E:\main.cpp  3  Info 783: Line does not end with new-line

     

    C:\PCLint>

    PCLINT已经工作了,是不是简单的难以让人相信。

    2.1.3.    最简单的标准用法

    修改被检查的文件E:\main.cpp,内容修改为:

    #include <stdio.h>

     

    void main()

    {

        printf("hello pclint\n");  

    }

    再次在命令行下输入:D:\>C:\PCLint\Lint-nt E:\main.cpp

    D:\>lint

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   E:\main.cpp

             _

    #include <stdio.h>

    E:\main.cpp  1  Error 322: Unable to open include file 'stdio.h'

     

    D:\>

    报错误,“不能找到头文件stdio.h

    当然PCLINT不可能也不应该知道到哪里去找stdio.hstdio.h所在的路径需要我们告诉它。

    如何告诉呢?

    通常的做法是在xxx.lnt文件中指定,然后指定使用这个xxx.lnt文件。

    最简单的是使用 c:\pclint\std.lnt 这个文件。

     

    2.2. std.lnt的配置:

    2.2.1.    std.lnt的默认内容

    C:\PCLint\std.lnt默认内容为:

    //NOTES: DON'T delete the comment string

    //author+++

    //au-sm.lnt au-ds.lnt au-misra.lnt

    //author---

     

    //compiler+++

    co-gnu3.lnt

    //compiler---

     

    //library+++

    lib-stl.lnt lib-w32.lnt lib-wnt.lnt

    //library---

     

    //alignment+++

    -si4 -sp4

    //alignment---

     

    3gTdrnc.lnt

     

    2.2.2.    修改std.lnt

    运行C:\PCLint\CONFIG.EXE(或者直接手工修改std.lnt

    最后生成的std.lnt内容为:

    //  Microsoft C and Visual C++ 6.x, -si4 -sp4,

    //  Standard lint options

     

     

    co-msc60.lnt

     

    // options.lnt  -si4 -sp4

    -i"E:\Program Files\Microsoft Visual Studio\VC98\Include"

    -i"E:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE"

    -i"E:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE"

     

    暂时将options.lnt 这行注释掉。

    注:如果生成的std.lnt内容与上面不一样,可以手工修改成上面那样。

     

    2.3. 使用std.lnt

    再次在命令行下输入:D:\> C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt e:\main.cpp

    C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt e:\main.cpp

    -i"C:\PCLint" -u std.lnt 指明使用std.lnt这个选项文件,至于std.lnt在什么目录,通过-i"C:\PCLint"告知。

     

    至此,我们已经学会了PCLINT的简单用法及两个选项:-i,-u

    -i 指明包含路径

    -u 指明使用哪些.lnt文件

     

    3.   其它开发工具下的配置

    前面我们掌握了命令行方式下PCLINT的使用方法,下面介绍在VC下面的配置及使用。

    3.1. VC下的配置

    新建一自定义工具项,名称为:PCLINT

    其中的Arguments为:-i"C:\PCLint" -u std.lnt env-vc6.lnt "$(FileName)$(FileExt)"

    Q:怎么知道要输入这样的参数了?

    A:从帮助中得知的,见文件env-vc6.lnt

    Q: env-vc6.lnt有什么作用?

    A:指定输出错误报告的格式,这个选项可以去掉,比如修改为:

    Arguments为:-i"C:\PCLint" -u std.lnt "$(FileName)$(FileExt)"

    3.2. 示例

    3.2.1.    testForPclint1

    新建一个最简单的Win32 Console Application,工程名testForPclint1,其中的main.cpp为:

    void main()

    {  

    }

    点击Tools菜单下面的PCLINT菜单项:

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   main.cpp

    }

     

    main.cpp(3): error 783: (Info -- Line does not end with new-line)

     

    --- Global Wrap-up

     

     error 900: (Note -- Successful completion, 1 messages produced)

    Press any key to continue

    第三行有个错误:error 783: (Info -- Line does not end with new-line)

    意思是说没有以新行结束。

    注:如果Arguments为:-i"C:\PCLint" -u std.lnt "$(FileName)$(FileExt)"

    则结果为:

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   main.cpp

    _

    }

     

    main.cpp(3) : Info 783: Line does not end with new-line

    Press any key to continue

     

    修改main.cpp为:

    void main()

    {  

    }<---即在这里加一个回车

     

    再次LINT,结果没有任何告警:

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   main.cpp

     

    --- Global Wrap-up

     

     error 900: (Note -- Successful completion, 0 messages produced)

    Press any key to continue

     

    3.2.2.    testForPclint2

    新建一个最简单的Win32 Console Application,工程名testForPclint2,其中的main.cpp为:

    #include "stdio.h"

     

    int main(int argc, char* argv[])

    {

        printf("hello\n");

    }

     

    点击Tools菜单下面的PCLINT菜单项:

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   main.cpp

    _

    }

    main.cpp(6) : Warning 533: function 'main(int, char **)' should return a value

        (see line 3)

    main.cpp(3) : Info 830: Location cited in prior message

    _

    }

    main.cpp(6) : Info 715: Symbol 'argv' (line 3) not referenced

    main.cpp(3) : Info 830: Location cited in prior message

    _

    }

    main.cpp(6) : Info 818: Pointer parameter 'argv' (line 3) could be declared as

        pointing to const

    main.cpp(3) : Info 830: Location cited in prior message

    _

    }

    main.cpp(6) : Info 715: Symbol 'argc' (line 3) not referenced

    main.cpp(3) : Info 830: Location cited in prior message

    Press any key to continue

    4个告警,修改main.cpp为:

    #include "stdio.h"

     

    int main(int argc, char* argv[])

    {

        (void)argc; // pc lint

        (void)argv; // pc lint

        printf("hello\n");

     

        return 0;

    }

     

    再次LINT,无任何告警了。

    PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004

     

    --- Module:   main.cpp

    Press any key to continue

     

    4.   使用批处理方法

    为什么要使用批处理?还不是为了使用更简单。

    我们在C:\PCLint建一个批处理文件lint.bat,内容为:

    @echo off

    C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt e:\main.cpp

     

    为了支持输入参数,修改为:

    @echo off

    C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt %1

     

    这时候我们不能简单输入D:\>lint.bat,而必须加上输入参数:

    D:\>lint.bat e:\main.cpp

  • 相关阅读:
    Amoeba for MySQL读写分离配置
    基于amoeba实现mysql数据库的读写分离/负载均衡
    Amoeba实现mysql主从读写分离
    OpenERP 的XML-RPC的轻度体验+many2many,one2many,many2one创建方式
    openerp用wizard导入excel数据
    OpenERP在product中增加外部网络链接图片
    OpenERP7.0安装后提示“not supported" ,如何去掉此提示
    windows命令行设置IP与DNS
    ubuntu开机自动启动xampp/lampp的两种方法
    [Python]网络爬虫(五):urllib2的使用细节与抓站技巧
  • 原文地址:https://www.cnblogs.com/tuantuan/p/940752.html
Copyright © 2011-2022 走看看