【正文】
typedef Flags Flags1。 in binary operation)D:\PCLint\MyTest\Test1\(15): error 639: (Warning Strong type mismatch for type 39。 // Warn Flag2 = Flag1}PClint for C/C++ (NT) Ver. , Copyright Gimpel Software 19852001 Module: D:\PCLint\MyTest\Test1\ f2 = f1。typedef Flags Flags2。 for strong type 39。 /* Two Warnings */}PClint for C/C++ (NT) Ver. , Copyright Gimpel Software 19852001 Module: D:\PCLint\MyTest\Test1\ scr[ i ][ col ] = BLANK。 39。 }例2:/* Types to define and access a 25x80 Screen.a Screen is 25 Row39。void main(){ Count i。Temperature39。 // OK, i is a Count pt[1] = 。typedef int Count。 in context: assignment) pt[1] = 。Temperature39。 // OK, ptt is a Count}PClint for C/C++ (NT) Ver. , Copyright Gimpel Software 19852001 Module: D:\PCLint\MyTest\Test1\ t[0] = t[1]。 // OK because of d flagTemperature *pt = t。 // strong type violationD:\PCLint\MyTest\Test1\(20): error 632: (Warning Assignment to strong type 39。 // strong type violation = 。 BitField c:1, d:2, e:3。 }如果改為://lint strong(B,Bool)include typedef int Bool。Bool gt(int a,int b){ if(a) return a b。 in context: assignment)D:\PCLint\MyTest\Test1\(12): error 530: (Warning Symbol 39。 // mistake but no warning}This programmer botch goes undetected by the piler because the piler is empowered by the ANSI standard to check only underlying types, which, in this case, are both the same (int).//lint strong(A,Count,Bool)include typedef int Count。WIN32_LEAN_AND_MEAN39。D:\PCLint\MyTest\Test1\(15): error 534: (Warning Ignoring return value of function 39。k, amp。 int i, k, n。) and use 2 // lines (line in error plus message).Width選項width(W,Indent)width(79,4) is the default setting.例:width(0) // don39。這個取決于你的編譯器。 q ) { *p = 3。 if(b==TRUE) {} return 0。 always evaluates to False [Reference: file D:\PCLint\MyTest\Test1\: line 15]) Module: D:\PCLint\MyTest\Test1\ Global Wrapup error 900: (Note Successful pletion, 2 messages produced)Tool returned code: 123在宏定義中添加Options屏蔽檢查:define for /*lint e(506, 774)*/if(0) {} else for例3:If you are usingdefine TRUE !0you will receive the message:506 Constant Value Booleanwhen TRUE is used in an arithmetic expression. (For C, TRUE should be defined to be 1. However, other languages use quantities other than 1 so some programmers feel that !0 is playing it safe.) To suppress this message for just this context you can use:define TRUE /*lint save e506 */ (!0) \/*lint restore */or the equivalent:emacro(506, TRUE)include define TRUE !0//define TRUE /*lint e506*/ (!0) /*lint restore*/int main(){ bool a = 1。 } if( naughty ) printf( Cheryl has been naughty %d times\n,naughty )。b39。g39。 (line 16) not subsequently referenced) Global Wrapup error 900: (Note Successful pletion, 5 messages produced)Tool returned code: 5例2:define for if (0) {} else for//define for /*lint e(506, 774)*/if(0) {} else for//lint +e774include include char Cheryl[] = gbgbbgbbgggb。 int b=0。s Work Bench Source Insight Editor Visual Slick Edit Turbo/Borland IDE under DOS Microsoft39。}。它不僅可以檢查出一般的語法錯誤,還可以檢查出那些雖然符合語法要求但不易發(fā)現(xiàn)的潛在錯誤。2 ...總體而言,配置向?qū)a(chǎn)生以下文件: A batch file which can also be copied into your PATH and which contains a reference to. An indirect lint file that will point to a piler options file and an options file and optionally other files and options.STD_...LNT A sequence of different versions of that the wizard can choose from later. A convenient centrally located options file that you will tend to use for most of your linting. A batch file optionally generated to be used to place the PClint executable in your PATH.配置向?qū)н€將從安裝目錄拷貝以下文件到配置目錄:co....lnt Compiler options file(s)env....lnt Environment options fileslib....lnt Library options fileslib....h Headers referenced by lib....lnt files.au....lnt Options files for author remended checksfile?.cpp A pair of test programs described in the next section.運行測試程序lin filea fileb將對filea和fileb進行代碼檢測:://lint w2 reduce the warning level to 2class X{static int a。s IDE Borland39。++文件。 (line 9) not subsequently referenced) int res = a/b。 for( p = Cheryl。 amp。b39。 *p。 //lint save e506 if (a == TRUE) printf(OK!\n)。 // warning only if +fpn q++。a39。PClint for C/C++ (NT) Ver. , Copyright Gimpel Software 19852001 Module: D:\PCLint\MyTest\Test1\ int n = foo(4,0)。Warning 616 will be issued if no ment at all appears between the two cases. If this is adequate protection, then just inhibit message 825.例2:t4 // Presume that tabs are every 4 stops編譯器適配編譯器適配文件All pilers are slightly different owing largely to differences in libraries and preprocessor variables, if not to differences in the language processed. For PClint, the key to coping with these differences is the selection and/or modification of one or two pilerspecific files provided on the distribution diskette.所有編譯器都存在一些差異,主要是庫(libraries)和預處理器變量(preprocessor variables)的差異。 if(i%3==0) fprintf(fp,\n)。D:\PCLint\MyTest\Test1\(13): error 534: (Warning Ignoring return value of function 39。 (pare with line 285, file C:\Program Files\Microsoft Visual Studio\VC98\Include\)) Global Wrapup error 900: (Note Successful pletion, 3 messages produced)Tool returned code: 3保留關(guān)鍵字ANSI C 一共有32個關(guān)鍵字,它們分別是: auto break case char const contiune default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile whileIn addition to the languagedefined keywords, the Microsoft pilers have added over the years a number of nonst