Today, we finally set up the pclint environment. In windows, we can directly use sis to write code and use pclint to check the code. Next we will introduce: <reproduced from: hi.baidu.com/qiupingwu> 1. What is PC-Lint? If you really don't know what it is? Please ask Google in private, but do not say it :-). To put it simply, PC-Lint is a good <Note 1> Software developed by Gimpel Software. You can call it a nitpicking tool, because it can perform much stricter (including but not limited to) syntax checks than compilers.In fact, this tool has two versions: a PC-Lint, is for PC machines (mainly dealing with Windows, MS-DOS, OS/2 and other systems), in the form of executable files; another name is FlexeLint, which is for other systems (such as Linux) and is released using the source code. Since FlexeLint is rarely seen, this article only introduces the use of PC-Lint. the latest version on the official web is 9.0, but it is also not easy to get, so this article only introduces PC-Lint8.0. we will use a work und to check the code in Linux. 2. Environment As mentioned above, PC-Lint is only applicable to Windows and OS/2, but C standardization is better, so it is slightly changed, PC-Lint is fully capable of dealing with the code for Linux systems. In addition to the operating system environment, you should also combine PC-Lint with the compiling/editing environment. now PC-Lint can be well integrated with most mainstream compilers and editors, which is very convenient to use. These two aspects will be discussed below. 2.1. Use with Linux In Linux, GCC is usually used as the C code compiler. to enable PC-lint to effectively check the code for Linux, you should select the correct header for it (. h) file. these files are usually stored in/usr/include and/usr/<X. y. z>/include directory. Since PC-Lint cannot run on Linux, You need to map the two directories above (for disk ing) to windows, so that the directory becomes z <Note 3>: /usr/include and Z:/usr/<X. y. z>/include. you can also copy the Linux header file directly to the Windows system. The system will prompt that the file name is duplicated, but these files are generally not used, just overwrite them directly. (I directly copied it to C:/pclint/usr in windows, but I didn't copy/usr/<x. y. z>/include) To enable PC-lint to recognize these two directories, add -Iz:/usr/include -Iz:/usr/3.4.3/include Two rows. In addition, because PC-Lint is designed for Windows, it will complain that some Linux header files are incorrect. since we do not advocate modifying the standard file, we should just make PC-Lint speak out for the moment. this can be done through the options. the following lines are added to the LNT file: -E716 // allow use while (1) // Bug in syslog. H, it define _ need_va_list _ macro -Efile (537, stdarg. h) -Emacro (530, va_start) // do not init first Parameter Modify the options. LNT file and use the GNU check rules. There should be the following line: C:/pclint/LNT/co-gnu3.lnt Assume that PC-Lint is installed in the C:/pclint directory. After configuring these settings, it is easier to check the Linux code on Windows. 2.2. Use with sourceinsight In sourceinsight, you can create a new command. In the custom commands window, enter the command name (such as lint) in the command, and then enter the command name in the run. C:/pclint/LINT-NT.EXE-u-ic:/pclint/lnt std. LNT env-Si % F In the pattern box, enter ^/(. */. [A-Za-Z] +/)/W/([0-9] + /).* Click Add. After that, you can directly execute this command to check the c file. 3. Configuration The configuration above is static. After the configuration is complete, it basically does not need to be changed. however, there are some special configurations for different projects. this section describes the configuration of a specific project. First, each project has its own header file. Therefore, you must specify the project's header file directory in STD. LNT. The format is as follows: -I For example: -IZ:/sw-new/src/license In addition, if some directories in the project are provided by a third party or we do not pay attention to the warning, you can specify these directories as library directories. The format is as follows: + Libdir (<library directory 1>, <library directory 2> ,...) For example: + Libdir (z:/usr/include, z:/usr/3.4.3/include, z:/mysql/include) For projects that have not been checked before, many warnings and errors may occur during the first PC-Lint check. in order not to bury useful errors in warnings. configure the global check level in lnt to display only serious errors. method: -W <number of levels> The larger the number of levels, the more input warning errors. We recommend that you increase the number gradually to eliminate errors and warnings step by step. For example -W1 Start. You can also use -E <error code> Checks for an error are temporarily blocked. 4. Avoid Fatigue There will also be a situation where, for some code, you are sure-think about whether your arguments are sufficient, don't rush to this conclusion Oh:-) ---- No problem, however, PC-Lint complained during each check. In this case, the PC-Lint can skip some checks by making special comments in the code. PC-Lint provides a large number of special comments that can be added to the Code. Fine-grained inspection control. The following lists some common options. For more options, refer to the PC-Lint user manual. note that these options must be added to the C code comments in the format of/* lint <xxxx> */. The lint must appear immediately after/*, and <xxxx> indicates the option, leave a space after option */. 1).-e (# [, #]...) is only valid for the next expression, A =/* lint-e (413 )*/*(Char*) 0; And A =/* lint-save-e413 */*(Char*) 0 /* Lint-restore */; Is equivalent. 2). -- e (# [, #]...) is valid for the entire expression, A =/* lint -- e (413 )*/*(Int*) 0 + *(Char*) 0; The output of two 413 messages is blocked, and the first 413 output is blocked by using-e (413. 3 ). -e {# [, #]...} valid for the next statement or statement. the impact scope of this usage is flexible: it is valid for the entire function before the function; it is valid for the value assignment statement before a value assignment statement; inIfOrWhileBefore the statement. 4 ). -- e {# [, #]...} it is valid for the entire code body in its {}, including the function body, class, and structure. if it is not in any {}, it is valid for the entire file (of course, from where -- e {} appears to the end of the file ). 5 ).! E # only valid for the row in which it is located. 6).-esym (#, sym [, sym]) shields the specified symbol for warning. 5. common error handling The following lists some common errors and solutions: 525 the error indent is prompted because the code is mixed with the TAB key. PC-Lint considers that the Code indent does not conform to the Code logic. change the code to a space. <Note 5>. The 715 symbol is not referenced because a call parameter or local variable in the function is not used. You can directly remove the local variable and place the ParameterIfStatement. 740 unusual type conversion is prompted. Generally, when the pointer type is converted, when the size of the Space indicated by the pointer before and after the conversion is inconsistent, you can add /* Lint-e (740 )*/ To block this warning. 818 the pointer parameter of the function is not modified within the function. The prompt is that the parameter is defined as a constant pointer.ConstIt seems that PC-Lint has a BUG when dealing with this problem, even ifConstThe modifier will continue to prompt this warning. In this case, the 818 warning should be blocked for the pointer parameter of this function by adding the method before the function starts. /* Lint-esym (818, pointer )*/ Add /* Lint + esym (818, pointer )*/ 827 inaccessible code, because inWhile(1 )/For(;), But the code will never be executed. The solution is to add /* Lint-unreachable */ <1> it is not because it was produced in the year of ox, but because it is really awesome. <2> This indicates the current GCC version, for example, 3.4.3. <3> assume that the disk is mapped to the Z disk. <4> the reason is that Linux File names are case-sensitive, while Windows files are case-insensitive. <5> this kind of work can be done by indent. Believe it, it can do well. |