Essential for strict procedures: LINT

Source: Internet
Author: User

 

Introduction to lint

 

 

LINT tool is a software quality assurance tool. Many large foreign professional software companies, such as Microsoft, use it as a program inspection tool, ensure that the LINT check is passed before the program is integrated into the trial version or delivered for testing. They require software engineers to turn on all the compilation switches when using LINT, if you must turn off some switches, you must give a legitimate reason to turn them off.

It is conceivable that if we use LINT to check the program when compiling the program for the first time after encoding and ensure that all LINT alarms are eliminated, we will not encounter so many alarms as today. Even today, if we can spare some effort to eliminate the LINT alarm in the program, it is easy to maintain this alarm-free status in the future. The improvement of program quality is self-evident.

PC-LINT is a product of gimpel software, where the content is very extensive, there are more than 300 options, involving all aspects of program compilation and syntax use. The purpose of this training material is to guide readers to get started, learn the basic use of PC-LINT, play a valuable role, let readers start from here to continue to study how to skillfully use the various options of PC-LINT, it can fully serve our development work.

1. Overview
If you want to define the next image point of the LINT tool, it is a more rigorous compiler. It not only checks common syntax errors as common compilers do, but also checks errors that, although fully compliant with syntax requirements, are likely to be potential and hard to find. See the following example:
Char * report (int m, int n, char * p) <br/>{< br/> int result; <br/> char * temp; <br/> long nm; <br/> int I, k, kk; <br/> char name [11] = "Joe Jakeson "; <br/> nm = n * m; <br/> temp = p = ""? "Null": p; <br/> for (I = 0; I 13: {<br/> k ++; <br/> kk = I; <br/>}< br/> if (k = 1) result = nm; <br/> else if (kk> 0) result = 1; <br/> else if (kk <0) result =-1; <br/> if (m = result) return (temp ); <br/> else return (name); <br/>}
The above code is a piece of effective Code Compiled with the general compiler, but there will be several warnings when compiled with a PC-LINT. First, the nul character is lost when the first row assigns a value to the name array. The multiplication precision of the second row will be inaccurate. The comparison of the second row is incorrect. The variable k of the second row is not initialized, the kk of row 15th May not be initialized, and the result of row 22nd May not be initialized. Row 23rd returns the address of a local object. This code can be compiled smoothly in most compilers. Manual debugging is required to continue searching for errors. If the program is large, it will be a cumbersome task, no one can be sure to find out all this type of problem, but the PC-LINT can only be done through a simple compilation, obviously saving us a lot of development time.

Next let's take a look at how to install and use PC-LINT.
2. How to install PC-LINT
PC-LINT software installation process is more complex, more options, the following according to the installation process, one by one to describe the meaning of each step.
0) if it is a zip file, expand the ZIP installation file to the directory C:/lint. in ins, Enter command prompt, first line Directory ing subst g: c:/lint. ins, and then go to G: To execute install. The other steps are the same as the following steps for installing a floppy disk.

1) insert the PC-LINT installation disk in A: Drive, enter A:/> install command, enter the start installation bar, press any key to continue, enter the PC-LINT introduction bar, and then press any key to continue.
2) enter the environment selection column, which has three options:
Windows NT/Windows 95
The MS-DOS (DOS extended)
OS/2 (32bit)
If WIN95, WIN97, WIN98, or WINNT is installed on your computer, select Windows NT/Windows 95. If
Select DOS for only DOS.
3) enter the installation directory selection bar. C:/> LINT is recommended. If you do not want to install it in this directory, enter the directory you want to install and press enter to confirm, if the directory to be installed does not exist, it will prompt you to create this directory. Here we select C:/> LINT
4) Select the disk drive where the installation disk is located. Here, select:
5) determine whether to select multiple compiler or compilation library configurations.
INT, select YES; otherwise, select NO. Then press enter to confirm.
6) you can see a compiler list and select your own compiler in this table. If the table does not have your own compiler, you can select the General compiler: Generic Compilers. Press enter to confirm. This option is reflected in the co-xxx.lnt file.
7) then, the installation program will allow you to select a memory model. You can select an appropriate memory model based on the actual size of your program and data zone. If the CPU is a 32-bit 68K series, select 32-bit Flat Module.
The options of the memory model are reflected in the STD. LNT file.
8) After selecting the memory model, you will see a list of database types. Here, select one or more libraries used for compilation. This option is reflected in the LIB-xxx.LNT file.
9) then let you select the author who has made important suggestions for using C ++ programming. After selecting an author, the options for his programming recommendations will be turned on. The options related to the author selection are reflected in the AU-xxx.LNT file.
10) the next step is to set the directory containing files. There are two options. The first option is to use the environment variable INCLUDE. The environment variable is set in the batch processing file. After the environment variable, each directory is separated by a semicolon. For example, you can set "INCLUDE = C: /MRI/MCC68K; D:/LAP/SRC/INC ". The second option is to use the-I option, and the-I option is embodied in STD. in the LNT file, each directory is guided by-I, and the directories are separated by spaces. For example, you can set "-IC:/MRI/MCC68K-ID:/LAP/SRC/INC ". If you select the-I option, the installer will then ask you to enter the directory containing the file.
11) If you have selected multiple compiling environments, you will be asked if you want to select more compiling environments. If YES is selected, the repeat will be started from step 1. If NO is selected, the compiler selection is terminated.
12) An OPTIONS file that reflects the display of global compilation information will be generated. LNT: The file is generated in two ways. One is that the installer explains several core OPTIONS one by one and asks if you want to cancel the option. If you choose to cancel the option, it will be reflected in OPTIONS. in the LNT file, the specific embodiment is to add-e before the information encoding, followed by 13th ~ Step 18 is the process of selecting core options one by one. If you select the second option, the installation file will generate an empty OPTIONS. LNT file, and you will add the necessary OPTIONS in the future.
13) Whether to disable the Boolean test alarm when assigning values, such as: if (a = f ()){...
14) Whether to disable the non-matching alarm between the signed amount and the unsigned amount during the assignment. Normally, this assignment will not cause problems. When you choose to disable the alarm information, alarms for mixed operations between other types of signed and unsigned volumes are still enabled.
15) When an integer is assigned to a smaller value than it, the latter will lose its precision. For example, assign an INT value to a CHAR. This step allows you to choose whether to disable this type of alarm.
16) whether to turn off the alarm with the left shifting symbol volume. Usually the PC-LINT will generate an alarm for all the movement of the amount of symbols, but the right shift is generally determined by a different CPU to determine whether to move the symbol bit into, left shift is generally will not produce any problem, you can disable the alarm.
17) calling a C function before it is defined or declared does not always produce errors. You can choose whether to disable this alarm option here. This option does not work for C ++ programs.
18) Whether to disable the alarm of "calling a nonexistent function prototype. Some programmers do not want to follow the strict original function definition conventions, but the PC-LINT will generate an alarm when calling an undefined function prototype, where you can choose to turn off the alarm.
19) after confirming the format of the OPTIONS. LNT file through the above steps, select the compiling environment. PC-LINT provides the ability to work in a variety of development environments, for example, in VC, BC, Source Insight. Let us select Source Insight here. After selecting this option, the installer will continue to ask if you want to select another environment. You can select one or more development environments based on the actual situation of your application. The selection of development environments is documented in the env-xxx.lnt file.
20) the installer generates a Lin. the bat file, which is a batch file that runs the PC-LINT, provides two ways for you to choose to run the file in any path. The first method is to let you choose to copy Lin. BAT to any path directory. When you run the lcopy. BAT file after installation, Lin. bat will be copied to your specified directory. The second method is to generate an lset. BAT file, run it to set the path each time before using the PC-LINT, or copy the content of the lset. BAT file to the autoexec. BAT file.
21) after the installation program is executed, the first thing is to execute the lcopy. BAT file in your installation directory. It copies some files from the installation disk to the installation directory, and sets the parameters in the file according to your selection during the installation process.
3. Lint a c file
3.1 Use the command line method for lint
If Lin. bat batch processing file lint, before lint should first look at the content of the batch processing file, contains the LINT-NT command and Command Options, you can modify, increase or decrease the options according to your own requirements. We can see that a STD is nested in this batch of commands. LNT file, in STD. the LNT file also contains Co. LNT, options. LNT and lib-stl.lnt files, in principle *. the LNT file can be nested without restriction. This type of file generally contains lint options. You can modify these files to modify the lint options. The options are executed in the order from left to right. Run the following command:
C:/ABC/src> Lin Alpha. C Beta. C gamma. c
Generally, for a program composed of multiple C modules, it is best to perform a lint check on each C Module unit first. When the unit Lint is executed, the following operations can be performed:
C:/ABS/src> Lin-u Alpha. c
Here, "-U" is the unit option. After "-U" is used, you can disable some alarms generated when multiple modules are checked, for example, "the function is not used" or "the function is not defined.
You can also directly use the LINT command instead of using LIN. BAT to process files in batches. The LINT command is LINT. EXE in DOS, LINT-NT.EXE in Windows95/NT, and LINT-OS2.EXE in OS2. To directly use the LINT command, you must set the path of the LINT directory before use. The best way is to add the path to the AUTOEXEC. BAT file. Other methods are the same as those for batch files. For example:
C:/abs/src> lint-nt-ic:/lint/std. lnt-OS (_ lint. tmp) *. c
3.2 use the development environment for LINT
You can also use the development environment to execute LINT operations. Generally, the development environment supports running executable files, but not necessarily supports running batch files. The following uses Source Insight, Ultra Edit, MSVC 6.0 illustrates how to implement LINT in the development environment.
3.2.1 integration in Source Insight
If you choose to use a development environment during installation, the installer will generate a env-xxx.lnt file under the directory you install, for example, there will be a env-si.lnt file when you select Source Insight. Open the file in the editor and explain in the comments at the beginning of the file how to integrate PC-LINT functionality into the development environment, the process of integration into Source Insight is as follows:
1) Select the "m Commands" command item from the Options menu.
2) Enter "PC-lint" in the Name column. In principle, this Name can be used as long as you can understand its meaning.
3) In the Run column, enter "c:/lint-nt-u-ic:/lint std env-si % f", where c: /lint is the installation directory for your PC-LINT.
4) Select "Iconic Window" and "Capture Output" in the Output column ".
5) Select "Save Files First" in the Control column ".
6) in the Source Links in Output column, select "Parse Links in Output", "File, then Line ".
7) in the Pattern column, enter "^/([^] */)/([0-9] + /)".
8) Click Add to Add the command. For example:
9) Open the LINT file under Source Insight and open the "Custom Commands" command item in the Options menu, in the "Command" column, select the "PC-lint unit check" Command to run.
I noticed that the parameters in the "Run" column are different from the above prompts. In fact, all my other weird parameters are put in c:/lint/std. lnt. Please note that no matter how you configure the parameters, you must not forget to include the si-env.lnt in your configuration file, otherwise you will not be able to make the error message and the automatic correspondence of the program.
For ease of use, you can also configure the Menu button to add it to the System Menu 0. This is a general
The Source Insight application is not described here.
Second, when I use Source Insight in NT, it seems that the integration fails. The reason is unknown. The above example is successfully tested under WIN 95.
If you want to modify the LINT option, you can directly modify it in the Run column or edit a special *. put the lnt file in the c:/lint directory and add the file name to the Run column, which is the same as the command line method.
3.2.2 integration in Ultra Editor
Select Menu | Advanced | Tool Configuration..., as shown in:
1) Click "Insert ",
2) Enter c:/lint-nt c:/lint/std. lnt % f in command line:
3) Fill in: PC-LINT in Menu Item
4) In Command Output, select (x) Output to List Box and (x) Capture Output.
5) Click "OK"
The configuration is successfully tested under UE6.0/NT 4.0.
3.2.3 integration in MSVC 6.0
The basic principles are the same:
1) Select menu | tools | customize .....
2) Select the Tools Tab:
3) Click the dotted box above the main dialog box to create a tool item.
4) input name: PC-LINT
5) input Command: c:/lint/lint-nt.exe
6) Input Arguments: c:/lint/std. lnt $ (FilePath)
7) Select (x) Use Output Window
8) Close
After that, there is a PC-LINT option under the Tools menu.
The following figure shows the tool configuration in the case of vc6/Win NT 4.0:
3.3lint options
Lint options can be placed in comments, for example:
/* Lint option1 option2... optional Commentary */
// Lint option1 option2... optional commentary
The options must be separated by spaces. The lint command must be in lowercase and followed by/* Or/. spaces are not allowed. If the option consists of parts similar to operators and operands, such as-esym (534, printf, scanf, operat or new), the last option is Operator new, therefore, there can be only one null value between operator and new.
Grid.
Options can also be placed in macro definitions, for example:
# Define divzero (X)/* lint-save-e54 */(X)/O)/* lint-Restore */
Many lint options include over 300, which can be divided into the following categories:
1) Options for disabling error messages
This option is used to prohibit generation of certain types of error information. The most common options are-E and + E.-E is to prohibit generation of certain types of error information, and + E is to restore generation of certain types of error information. You can run msg.exeunder the lintdirectory to get the msg.txt file. This 5000-row-long file contains all the error message numbers and explanations.
-W is not displayed for all alarms greater than the level.
-Wlib () does not display any warning information about the number of library functions that is greater than the level. We can use-wlib (0) to shield the warning information of all library functions.-wlib (1) only displays syntax errors in library functions.
-Esym (#,) can block an alarm message for a specific symbol.
2) variable type and size options
The size of variable types (such as short integer and integer) varies with the target machine and compilation system. This type of option is used to set the variable type size for the target machine. Because the default settings match most compilers, these special settings are usually not needed and are only used in special target machine structures. For example, for an M68000 target machine, its int type and pointer type are usually 32bit. In this case, you should use the option:-si4
-Sp4. The current value of these size parameters can be obtained through the help screen. For example, you can enter the following command line:
Lin-si4-sp4?
3) lengthy information options
Lengthy information refers to some information generated in the LINT process related to the compilation process, rather than the real alarm information and error information. Whether to generate the information can be determined by the-v and + v Options. + V is used to generate the information, and-v is used to disable the information. In this set of options, except for + v, all other options can disable the + v option.
4) Tag options
The options starting with + f, ++ f,-f, and -- f are tag options. Their logical meanings are as follows:
+ F...: Set the flag to 1 and set it to ON
-F...: Set the flag to 0 and OFF.
+ + F...: the flag is increased by 1.
-- F...: Mark minus 1
The next two are used when you want to set a flag to ON locally without affecting global settings. For example, you can use:
/* Lint ++ flb */
Int printf ();
/* Lint -- flb */
There are many types of tag options. The basic meaning is to enable or disable certain types of syntaxes. For example, you can use abbreviation struct names, anonymous consortium, and C ++ compiling for all modules.
5) message display options
The message display option defines the message output format. The options include message height, message width, and Message format.
6) Other Options
There are many other options and there are great differences among them. I will not introduce them here. I suggest you take a look at PC-LINT. Chapter 5 provides a detailed description of each option. Lint itself also has some instructions, lint-nt 2> lint.txt, and then press a few carriage returns to generate a description file of the lint option.
4. LINT multiple C files under a project
4.1 why LINT multiple C files
In the initial stage of program coding, we may only care about the syntax issues in a single C Module. After the programming stage, for programs composed of multiple C modules, we want to know whether there are Syntax problems between modules after multiple modules are connected together. At this time, although the compiler can give some warnings, but the PC-LINT connection can give more warnings. In addition, when we can ensure that several of the modules are relatively stable and the other modules are still faulty, We can first compile several stable modules and connect them into a target file, after each modification, the file is compiled separately and then connected to the total target file.
4.2 How To LINT multiple C files under a project
Like the compilation tools we usually use, the PC-LINT will first compile each C file to generate an intermediate target file when compiling and connecting multiple C files *. and then connect all the lob files together. LOB is the abbreviation of Lint Object Module. This file contains all the external information of a C or C ++ module. There are three options to generate a LOB file:-u. To generate a LOB file using LINT, you must add the-u option; the second option is the-zero or-zero (500) option. This option must be added to ensure that the LOB file can be generated when the module has an error; the third type is-oo [(filename)]. filename is the name of the generated LOB file. It can be added or removed after-oo. If this parameter is not added, the LOB file name is the same as the name of the original C Module, for example:
Lint-u alpha. c-oo (a1)
The generated LOB file name is a1.lob.
Lint-u alpha. c-oo
The generated LOB file name is alpha. lob.
LINT multiple C modules in a project. In the user's source program directory, three files are generally required: one option file (*. lnt), a batch processing file (*. bat) and a MAKEFILE (*. mak ). The following describes how to create these files.
1) Option file (*. lnt)
As mentioned earlier, you can list all the common options that you use in each lint c file in this file. The options take effect from left to right, from top to bottom. This type of files can be nested layer by layer, and there is no limit on the number of nested layers. For example, make. lnt file:
-IC:/lint
Std. lnt
+ OS (temp)
-E46
+ Vm
-Zero
2) batch file (*. bat)
When creating a batch file, you must call the TCMAKE. EXE file and MAKEFILE file in the file, such as the lintmake. mak file:
@ Echo Lint Making 'makelap ':
Tcmake-flintmake. mak
@ Echo End of making
3) MAKEFILE (*. mak)
The TCMAKE syntax used by MAKEFILE is the same as the syntax format of the MAKEFILE file used for development and compilation. For example, the following lintmake. mak file:
MCCPATH = c:/mcc68k <br/> OPTION =-u make. lnt-oo <br/> GLOBLE = OS. h l2lap. h <br/> mail_depend = $ (GLOBLE) q931.h mail. h <br/> lapmain_depend = $ (GLOBLE) l1pubdef. h q931.h mail. h <br/> lapos_depend = $ (GLOBLE) <br/> fhdlc1_depend = $ (GLOBLE) cpuhdlc. h bd_prar.h q931.h <br/> OBJ = mail. lob lapmain. lob lapos. lob fhdlc1.lob <br/> project. lob: $ (OBJ) <br/> lint-nt make. lnt-e768-e769 *. lob <br/> mail. lob: mail. c $ (mail_depend) <br/> lint-nt $ (OPTION) mail. c <br/> lapmain. lob: lapmain. c $ (lapmain_depend) <br/> lint-nt $ (OPTION) lapmain. c <br/> lapos. lob: lapos. c $ (lapos_depend) <br/> lint-nt $ (OPTION) lapos. c <br/> fhdlc1.lob: fhdlc1.c $ (fhdlc1_depend) <br/> lint-nt $ (OPTION) fhdlc1.c
4.3 simple LINT multiple files
Assuming that our project is not complex, we can afford the overhead of lint all the files every time, or do not use the above Regular usage. In practice, I found that placing all the *. c files in a lint command can also accomplish the purpose of the entire lint project.
For example:
Lint-nt c:/lint/std. lnt AllMySource. lnt
Include all the source files in your project in AllMySource. lnt:
A1.c
A2.c
A3.c
Note that the-u option is not required in the std. lnt file. Because we have provided all the information

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.