首先得到vs2005.lnt, co-msc80.lnt, env-vc8.lnt三个文件,具体内容看下文
步骤
1. 安装pc-lint或拷贝已安装的文件到已指定目录
2.VS2005->tools->external tools
3. add pclint(名字不定)
4. commond,选择pclint的exe文件
5.arguments
-i“vs2005.lnt文件目录” -u vs2005.lnt "$(ItemDir)$(ItemFileName)$(ItemExt)"(-i与后面内容没有空格)
其他用刀的lnt文件需要同vs2005.lnt在一个目录下
6 使用PC-Lint时可能会遇到很多库的头文件的错误,特别是在VS中。这时可以通过设置PC-LINT.exe的参数屏蔽库文件的错误。一般为PC-LINT.exe -wlib(x)
-wlib(0) 不生成任何库信息
-wlib(1) 只生成错误信息(当处理库的源代码时)
-wlib(2)
生成错误和告警信息
-wlib(3) 生成错误、告警和其它信息(这是默认设置)
-wlib(4) 产生所有信息
另外,如果你测试时不想看一下info类的信息,可以在命令中增加-wx来屏蔽不需要显示的信息:
-w0 不产生信息(除了遇到致命的错误)
-w1 只生成错误信息 -- 没有告警信息和其它提示信息
-w2 只有错误和告警信息
-w3 生成错误、告警和其它提示信息(这是默认设置)
-w4 生成所有信息
一般情况下我先使用-w1再用-w2,最后用-w3
vs2005.lnt内容,注意-i和后面内容之间没有空格
au-sm.lnt
co-msc80.lnt
lib-mfc.lnt
lib-stl.lnt
lib-w32.lnt
lib-wnt.lnt
lib-atl.lnt
options.lnt
-si4 -sp4
-i"E:/Program Files/Microsoft Visual Studio
8/VC/include"
-i"E:/Program Files/Microsoft Visual Studio
8/VC/atlmfc/include"
-i"E:/Program Files/Microsoft Visual Studio
8/VC/PlatformSDK/include"
-i"E:/Program Files/Microsoft Visual Studio
8/SDK/v2.0/include"
-i"F:/exercises/set/set"
co-msc80.lnt
// co-msc80.lnt
// Compiler Options for Microsoft C Version
14.00
// (32 bit version)
// This file contains options to
allow PC-lint to process source
// files for your compiler. It is used as
follows:
//
// lint co-msc80.lnt
source-file(s)
//
-cmsc
-si4 // integers are 4 bytes
-sp4
// pointers are 4 bytes too.
// We now support __declspec
directly so that the following
// option is now commented out. If
trouble ensues you can
// once again disable __declspec through this
option.
// -d__declspec()= // ignore this
construct
-d_declspec=__declspec // the single '_' version is occasionally
used
// while processing compiler (library) header files
...
-wlib(1) // sets the warning level within library headers to 1
// (no warnings, just syntax errors). Comment out if you
// are
actually linting library headers. This
// option makes obsolete
options of the form -elib(axxx) where
// xxx >= 400 which may be
retained for historical reasons.
-elib(19) // useless declarations (lone
semicolons)
-elib(123) // function-like macro name used as non
macro
-elib(652) // suppress message about #define of earlier declared
symbols
-elib(762) // suppress message about multiple identical declarations
and
-elib(760) // suppress message about multiple identical macro
defs
-elib(514) // allow #if <boolean> |
<boolean>
-elib(553) // undefined preprocessor variables assumed
0
-elib(726) // extraneous comma in enum definition
// SREGS,
WORDREGS, BYTEREGS are defined in both bios.h and dos.h
// and accordingly
you MAY get type differences based on 'origin'.
// If so, use the following
options:
// -etd(origin)
//
-elib(770)
-format=%(%f(%l)/s:/s%)%t/s%n:/s%m
// error format
similar to MSC
// Note that %c can also be used to specify
column
-e46 // allows bit-fields to be other than int or
unsigned
+fan // allow anonymous unions
+fdi // Use directory of the
including file
+fbo // enable the bool type
-fdh // do not append a
.h to header names
-esym(123,min,max) // allows users to use min, max as
variables
+rw(__inline) // activate the __inline keyword
+ppw(import)
// activate #import
-d_inline=__inline // _inline is the same as
__inline
-sld10 // sizeof(long double) is
10.
-function(exit,_exit) // _exit() is like
exit()
-function(exit,_assert) // _assert() is like
exit()
-emacro(506,assert) // don't warn about constant value
Boolean
-emacro(734,putc) // don't complain about items being too
large.
-emacro(415,_FP_SEG) // access of out-of-bounds
pointer
-emacro(740,FP_SEG,FP_OFF) // unusual
casts
-emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661,
662
// 796 and 797 (out-of-bounds
errors).
-emacro((???),va_start) // the same applies to
va_start
-emacro(413,offsetof) // use of NULL pointer creates a
stir
-emacro(545,offsetof) // addressing an array member is
OK
-e793 // inhibit 'ANSI limit reached' --
// limits
are impractically low with MSVC headers
-esym(628,eof) // failure to provide
argument information for eof()
-esym(773,L_tmpnam) // defined with an
unparenthesized '+'
// The following functions exhibit variable return
modes.
// That is, they may equally-usefully be called for a value
// as
called just for their effects. Accordingly we inhibit
// Warning 534 for
these functions.
// Feel free to add to or subtract from this
list.
-esym(534,close,creat,fclose,fflush,_flsbuf,fprintf,fputc)
-esym(534,fputs,fscanf,fseek,fwrite,lseek,memcpy,memmove,memset)
-esym(534,printf,puts,scanf,sprintf,sscanf,strcat,strcpy)
-esym(534,strncat,strncpy,unlink,write)
//
These are the wide char variants of printf-scanf family
-wprintf( 1,
wprintf )
-wprintf( 2, fwprintf, swprintf )
-wscanf( 1, wscanf
)
-wscanf( 2, fwscanf, swscanf )
// The following options are used to
adjust our function mimicry to
// the actual library as provided by
MS.
-function( wcstombs(1) ) // remove the check for a NULL first arg to
wcstombs()
// The following options are required by most compilers
to
// noiselessly process iostream.h
-elib(1717) //empty
prototypes
-elib(522) //function return value ignored
-elib(1053)
//prototypes cannot be distinguished
-elib(1721) //unusual operator =()
declaration
-elib(1720) //assignment op has non-const
parameter
-elib(655) // bitwise operator combining compatible
enum's
-elib(641) // converting enum's to int
-elib(537) // repeated
include file (ios.h)
-elib(1511) // member (rdbuf) hides nonvirtual
member
-elib(1712) // default constructor not defined for
class
-elib(1736) // redundant access specifier
d_NATIVE_WCHAR_T_DEFINED
-esym(1702,operator<<,operator>>) //
both a member and an ordinary function
// These functions return things
that are frequently
ignored.
-esym(534,*operator<<,*operator>>)
// The
following additional options seem to be needed.
-elib(506) // constant
value Boolean
-elib(620) // el or one? (some constants end in 'l' not
'L')
-elib(648) // overflow in computing constant (3<<16)
-elib(659)
// nothing fold_NATIVE_WCHAR_T_DEFINEDlows '}' on some line
-elib(723) //
suspicious use of '='
-elib(747) //significant prototype
coercion
-elib(740) //unusual pointer casts
-elib(1007) // virtual
functions within extern "C" block
-elib(1029) //default argument repeated --
can't dist. char, signed char
-elib(1055) //call to rdbuf()
questioned?
-elib(1504) // apparently useless structs
-elib(1708,1709) //
minor C/C++ declaration conflict
-elib(1707) // operator new declared w/o
'static'
-elib(1722) // assignment op does not return
reference
-elib(149) // default argument found in C code.
-elib(578) //
declaration of time hides delaration of global time().
-elib(761) // two
equivalent typedef declarations
-elib(1065) // same name declared as "C" and
not "C"
-elib(1066) // same name declared as "C" and not
"C"
-elib(1704) // constructor with private access
declaration
-elib(1735) // default parameter within virtual
function
-elib(773) // macros that look like unparenthesized
expressions
-elib(806) // 1-bit bitfields typed int
-elib(1501) //
0-length data members
-elib(1510) // base class has no
destructor
-elib(1516) // data member hides inherited member
-elib(1509)
// base class destructor is not virtual
// Special Notice: You may be
receiving mysterious 1058 errors
// when you use "iomanipulator"s. For
example:
// cout << setw(4) << 4;
// results in Error 1058
(assigning a const to a ref) because the
// manipulator setw returns a
non-lvalue which is assigned to a reference.
// This reflects an oversight
in the Microsoft header file: iomanip.h
// Therein you may change the
declaration:
// friend ostream& operator<<(iostream& s,
IOMANIP(T) & sm) { ...
// to:
// friend ostream&
operator<<(iostream& s, const IOMANIP(T) & sm) { ...
// to
reflect the fact that sm is not modified by this
function.
-d_INTEGRAL_MAX_BITS=64 // denotes support for
__int64
+fll // enable long long
-d__STDC__=0 // Starting
with 2.0, the tests within Microsoft header
// files for __STDC__ are
of the form #if rather than #ifdef
-dWIN32 // this is necessary
because without WIN32 being defined
-d_WIN32 // a very gross syntax
error is exposed in the objbase.h
// ... definition of function
operator ==(). Alternatively,
// ... repair the function
definition.
-dDBG=0 // There is a #if test made for this
variable.
/* The option -d_NEW_ previously appearing in this spot is no
longer
recommended as it nullifies the <new> header and because of
this
prevents definition of 'bad_alloc' among other
things.
*/
/* DLL's or Multithreads? Enable the
following:
-d_AFXDLL // making a DLL
-d_DLL //
ditto
-d_MT // multi-thread
*/
/* At one time we
indicated that wchar_t was predefined by using
the option +fwc but then
because to suppress the Microsoft headers
from redefining it we used the
option -d_WCHAR_T_DEFINED
But this in turned created a rare problem so
now we just leave it
undefined.
*/
// In the following option
we define __uuidof() and suppress
// Errors 50 and 69 and 1924 in exprs.
containing same
-d"__uuidof()= /*lint --e(50,69,1924) */
(_GUID)0"
-esym(123,FD_SET) // defined as macro and as
typedef
-esym(1726,endl,ends) // taking the address of an overloaded
function
-esym(18,Data_t::Data_t) // definition not matching
declaration
-elib(10) // expecting ')' -- comdef.h has a: #if
defined( id
-elib(43) // vacuous array within
_MIDL_FORMAT_STRING
-elib(602) // benign comment within
comment
-elib(657) // declaring "anonymous struct" in union
_LARGE_INTEGER
-elib(799) // long numerical constant for max.
__int64
-elib(1502) // nothrow has no data members
-elib(1505) //
no access specifier in base class specifier
-elib(1515) //
AFX_THREAD_STATE member has no default constructor
-elib(1706) // Unusual
declaration with a scope operator
-elib(1725) // data member is a
reference
-elib(1548) // conflicting exception
specifications
-elib(1737) // hiding global operator
new
-elib(1739) // binary operator should be non-member
function
-elib(1748) // non-virtual base class included
twice
-elib(1759) // post-fix operator returns a reference
// Add
elements of ole automation
lib-ole.lnt
// Options required for
.net
-d_stdcall=__stdcall // make _stdcall equivalent to
__stdcall
-d__interface=class // treat an interface the same as a
class
-d__unaligned= // pass over the __unaligned
keyword
-d__w64= // ignore this identifier
// Make sure you
define your architecture type by unleashing one
// of the following
defines:
-d_X86_
//-d_MPPC_
//-d_PPC_
//-d_IA64
//-d_MIPS
//-dMIDL_PASS
//-d_ALPHA_
-esym(40,DLGPROC) // used before being
defined
-elib(146) // assuming binary
constant
-elib(1015) // GetDefaultThreads not found in
class
+ppw(using) // ignore #using for
now.
-d__pragma(x)= // ignore the pragma
extension
+rw(__thiscall,__ptr64) // additional
qualifiers
-"d__identifier(x)=___identifier x"
// treat C++ keyword x as an identifier
-elibsym(1512) // base class
destructor not virtual
-d_MSC_VER=1400 // compiler version (in
decimal)
-d_MSC_FULL_VER{140050727} // full compiler version
#
-d_MSC_EXTENSIONS{1} // Change value to 0 if not using
extensions
-d_M_IX86=600 // assume Intel 80386 architecture -- modify to
suit
// These two are defined only when the user compiles with the
//
/Zc:wchar_t option for VC8. However, we have found
// -d_WCHAR_T_DEFINED
created a rare problem. So, now, we just leave
// them undefined. If the
user *really* wants to deal with the issues
// these options raise, they can
uncomment them.
//-d_NATIVE_WCHAR_T_DEFINED{1}
//-d_WCHAR_T_DEFINED
-dinitonly= // Compiler should catch
miss-uses.
// Lint can just skip over it.
-"dliteral=static
const" // Documentation says they are
//
equivalent for member data.
// When compiling with /J, use:
//+fcu // Plain char is unsigned
//-d_CHAR_UNSIGNED
// When compiling with /clr, /clr:pure or
/clr:safe, use:
//-d__cplusplus_cli=200406 // for all 3
//-d_M_CEE_PURE // for /clr:pure
//-d_M_CEE_SAFE
// for /clr:safe
//-d_MANAGED // for /clr
// When
using any /clr form, use:
//-d_M_CEE
// When compiling with /GR,
use:
//-d_CPPRTTI //Enable Run-Time Type Information
// When
compiling with /GX, use:
//-d_CPPUNWIND //Enable Exception
Handling
// When compiling with an /arch option, use:
//-d_M_IX86_FP=1 // For /arch:SSE
//-d_M_IX86_FP=2 // For
/arch:SSE2
// When compiling for Win64, use:
//-d_WIN64
//
When compiling with /Wp64, use:
//-d_Wp64 // 64-bit
portability
// Be sure to define your platform if any of the following
apply:
//-d_M_ALPHA // For DEC ALPHA platforms
//-d_M_IA64
// For Itanium 64-bit processors
//-d_M_X64 // For x64
processors
// When compiling with the /RTC option, use:
//-d__MSVC_RUNTIME_CHECKS // Using such checks
// When compiling with
/openmp, use:
//-d_OPENMP=200203 // OpenMP specification date
//
When compiling with /Zl, use:
//-d_VC_NODEFAULTLIB // Omit default
library name in *.obj file
//__try_cast is like dynamic_cast (except the
former throws where
//the latter returns
0).
-d__try_cast=dynamic_cast
//Partial support for the "old" (VC++
2003) Managed Extensions
//syntax:
+rw( __gc, __value, __nogc, __pin
)
-$ // $ can be used in identifiers
+rw( __allowed_on_parameter
)
+rw( __allowed_on_function )
+rw( __allowed_on_typedecl )
+rw(
__allowed_on_return )
+rw( __allowed_on_struct )
+rw(
__allowed_on_function_or_typedecl )
+rw( __allowed_on_field )
+rw(
__allowed_on_parameter_or_return )
+rw( __allowed_on_function )
//+rw(
*type_traits ) //type traits support
//-header(co-msc80.h) // implicitly
includes <typeinfo>. (Needed because
// MSVC 8
implicitly declares class type_info.)
env-vc8.lnt
/*
env-vc8.lnt: environment parameters for Microsoft's Visual C++
8.0
If you are using Microsoft Visual Studio 2005 and you wish to
invoke
PC-lint from that environment then add one or more commands to
the
Tools menu as follows.
Simple Check
------------
For example, to add a simple facility to lint the
current file you
may do the following:
1. From the Tools Menu
choose "External Tools ..."
2. Click the "Add" button.
3. You
will now be able to enter the fields of this Tool.
Modify them so
that they approximate the following:
Title: PC-lint (Simple
Check)
Command: c:/lint/lint-nt.exe
Arguments: -i"c:/lint"
std.lnt env-vc8.lnt "$(ItemFileName)$(ItemExt)"
Initial Directory:
$(ItemDir)
X_Use Output Window __Prompt for arguments __Close on
exit
Please note that you will have to change the "Command:" path
if the
PC-lint Installation Directory is anything other than c:/lint
and
you will have to change the "Arguments:" line if the
Configuration
Directory is anything other than c:/lint
4.
Select OK to return to the main environment.
This will result in the
Tools menu containing the additional item
"PC-lint (Simple Check)".
Checking 'X' on 'Use Output Window' is
important because in this way you
can advance from error to error
using the F8 key (Shift F8 to
reverse).
Strings of the form $(...) are called macros and can be
typed in
directly as shown or can be selected from a menu by
clicking
a right arrow in the dialog box. $(ItemFileName) refers to
the
file name of the currently edited file without its path and
without
its extension. $(ItemExt) is its extension. $(ItemDir)
represents
the file's directory.
You will probably want to
advance your new tool upward into the initial
position of all tools while
you are testing and modifying the command.
You can do this by using the
"Move Up" button that appears on the External
Tools dialog.
The benefits of using "Initial Directory" are that file-names in lint
error messages will not be so long, and, also, this directory can contain
a std.lnt that overrides the global std.lnt in the Configuration
Directory.
This Simple Check is fine to check stand-alone modules but
to check
projects or to unit check modules that are in projects we need
to
go a bit further ...
Project Creation
----------------
To lint an entire project we will need the names of
all the modules
in the project. Visual Studio keeps these names (as well
as some
appropriate options such as define options (-d...) and include
options
(-i...) in a file named NAME.vcproj in the current project
directory.
NAME is the name of the project and is identified by the
macro
$(TargetName). PC-lint can read the .vcproj file and generate
the
appropriate .lnt file. We recommend creating a tool for this
purpose.
For this tool follow the steps 1-4 doing exactly the same thing
as
above except in step 3, the information entered should be:
Title: PC-lint (Project Creation)
Command:
c:/lint/lint-nt.exe
Arguments: -v -os("$(TargetName).lnt")
"$(ProjectFileName)"
Init. Dir.: $(ProjectDir)
__Use
Output Window __Prompt for arguments x_Close on exit
You will need
to have an active project before this will work.
If you don't already
have one you can obtain an active project
from the Solutions Explorer.
You then click the newly added
"PC-lint (Project Creation)" tool on the
tools menu to create
NAME.lnt.
The file created is an ASCII
file and we recommend that you open it
within the IDE and examine it for
any obvious flaws. This is your
chance to make any necessary
modifications to the file as the process
of conversion may be less than
perfect.
Project Check
-------------
Interestingly,
by opening up the NAME.lnt file created above and
running the Simple
Check described earlier you have the equivalent
of a full project check.
However, we prefer to create a special
Project Check tool.
Now
that we have a project file we can create a new tool called
"PC-lint
(project check)". For this tool again follow steps 1-4 doing
exactly the
same thing as above except in step 3, the information
entered should
be:
Title: PC-lint (Project Check)
Command:
c:/lint/lint-nt.exe
Arguments: -i"c:/lint" std.lnt env-vc8.lnt
"$(TargetName).lnt"
Init. Dir.: $(ProjectDir)
X_Use
Output Window __Prompt for arguments __Close on exit
Unit
Check
----------
You can almost do a unit check on any single
module by using the
Simple Check scheme suggested above. The only
problems are that you
will need a -u option and you will not have the
benefit of any -d or
-i options that have been placed into NAME.lnt
created in the Project
Creation step. For this reason we suggest the
following tool for
doing a unit check of any module that is part of a
project and for
which a .lnt project file has been generated.
Title: PC-lint (Unit Check)
Command:
c:/lint/lint-nt.exe
Arguments: -i"c:/lint" std.lnt env-vc8.lnt --u
"$(TargetName).lnt" "$(ItemPath)"
Init. Dir.:
$(ProjectDir)
X_Use Output Window __Prompt for arguments __Close on
exit
Note that $(ItemPath) will provide a complete path name and in
the
absence of a project.lnt file it would cause full path names
to
appear in messages. But a side effect of using the project
file
with the --u option means that we adopt the shorter names
used
in the project file.
Suppressing Messages
----------- --------
Suppressing messages is normally done by adding
message suppression
options to a file. For example, -e550 will suppress
message 550.
There are numerous other options to suppress
messages.
As the documentation indicates, the file
c:/lint/options.lnt
(where c:/lint/ is the Configuration Directory)
is the presumed container
of your overall suppression policy. (Note:
options.lnt is referenced
by std.lnt). Add a message suppression here
and
you will affect all linting employing that configuration.
To suppress messages for a particular project (or for all projects
within
a given project directory) you may do the following:
Create a file
std.lnt that is contained in the project directory.
Make it refer back to
the std.lnt in the Configuration Directory.
Then add additional message
suppression options or indeed any options
you want. For example it might
contain:
c:/lint/std.lnt // reference to original
std.lnt
-e550 // project-specific
option
In this way suppression is limited to a particular
project.
Tool Bar
--------
You also have
the option of creating a PC-lint toolbar within your Visual
C++ IDE.
First, create one or more tools as described above. You
will need to
know the number(s) of the tool(s) you want to place on
the tool bar.
This can only be done by the painful and laborious
task of counting.
Using the list provided by "Tools"/"External Tools",
jot down the numbers
(starting with 1 at the top) of all the tools
to be added to the tool
bar. We recommend placing all the PC-lint tools
on a single tool bar.
Then select Customize from the Tools menu.
Select the Toolbars tab and
click the New... button.
Give the Toolbar a name (E.g., PC-lint) in the
dialog box provided and
click "OK". Confirm that the new toolbar is now
floating on the
desktop and that a check has been placed in the check box
next to the
new toolbar name. Then click on the Commands tab and in the
Categories
box, scroll down to and click "Tools". In the Commands box,
scroll down
to the appropriate external command number(s) corresponding
to the
PC-lint commands you jotted down earlier. Drag the commands from
the
Commands box to the toolbar. Their numeric name will change to
the
logical name.
If you want to add a button image to the
toolbar, you can choose one
via the Modify Selection button. Click Close
and you now have your
own PC-lint for C/C++ button. (Note: If you change
the location of
the PC-lint menu item on the Tools menu, you will change
the subscript
and you will need to change the button(s) on the
toolbar.)
*/
-"format=%(%F(%l):%) error %n: (%t -- %m)"
// Messages will contain
// file information (%F), the line number
(%l), the
// message number (%n), message type (%t) and message text
(%m).
-hF2 // Make sure we ALWAYS provide file information ('F') and
use 2
// lines (one for the source line in error and one for the
message).
-width(0) // don't break messages at any particular
width
-t4 // Presume that tabs are every 4 stops
+e900 //
issue a message at termination.