The lint program is a static analyzer. It cannot evaluate the runtime consequences of the dependencies it detects. Certain programs, for instance, may contain hundreds of unreachable break statements that are of little importance, but which lint flags nevertheless. This is one example where the lint command-line options and directives--special comments embedded in the source text--come in:
You can invoke lint with the -b option to suppress all the error messages about unreachable break statements.
You can precede any unreachable statement with the comment /* NOTREACHED */ to suppress the diagnostic for that statement.
The lint options are listed below alphabetically. Several lint options relate to suppressing lint diagnostic messages. These options are also listed in Table 5-5, following the alphabetized options, along with the specific messages they suppress. The options for invoking enhanced lint begin with -N.
lint recognizes many cc command-line options, including -A, -D, -E, -g, -H, -O, -P, -U, -Xa, -Xc, -Xs, -Xt, and -Y, although -g and -O are ignored. Unrecognized options are warned about and ignored.
Turns on verbose mode, showing each component as it is invoked.
Shows each component as it is invoked, but does not actually execute it.
Suppresses certain messages. Refer to Table 5-5.
Suppresses certain messages. Refer to Table 5-5.
Creates a .ln file with the file name specified. These .ln files are the product of lint's first pass only. filename can be a complete path name.
Creates a .ln file consisting of information relevant to lint's second pass for every .c file named on the command line. The second pass is not executed.
Specifies the directory dir where the lint output files (.ln files) will be placed. This option affects the -c option.
Treats all warnings as errors. The result is that both errors and warnings cause lint to exit with a failure status.
Check structural arguments passed by value; Check portability to environment for which the size of long integers and pointers is 64 bits.
l is a comma-separated list of checks that consists of one or more of the following:
Perform all of errchk's checks.
Perform none of errchk's checks. This is the default.
Check portability to environment for which the size of long integers and pointers is 64 bits and the size of plain integers is 32 bits. Check assignments of pointer expressions and long integer expressions to plain integers, even when explicit cast is used.
Perform none of errchk's longptr64 checks.
The values may be a comma separated list, for example -errchk=longptr64,structarg.
The default is -errchk=%none. Specifying -errchk is equivalent to specifying -errchk=%all.
Perform none of errchk's structarg checks.
Use this option to enhance the maintainability of code. If -errchk=parentheses returns a warning, consider using additional parentheses to clearly signify the precedence of operations within the code.
Issues a warning when a larger integer is assigned to a smaller integer. These warnings are also issued for assignment between same size integers that have different signs (unsigned int = signed int).
Check structural arguments passed by value and report the cases when formal parameter type is not known.
Specifies the format of lint output. f can be one of the following: macro, simple, src, or tab.
Table 5-1 The -errfmt Values
Value |
Meaning |
---|---|
macro |
Displays the source code, the line number, and the place of the error, with macro unfolding |
simple |
Displays the line number and the place number, in brackets, of the error, for one-line (simple) diagnostic messages. Similar to the -s option, but includes error-position information |
src |
Displays the source code, the line number, and the place of the error (no macro unfolding) |
tab |
Displays in tabular format. This is the default. |
The default is -errfmt=tab. Specifying -errfmt is equivalent to specifying -errfmt=tab.
If more than one format is specified, the last format specified is used, and lint warns about the unused formats.
Enables the reporting of certain messages for header files when used with -Ncheck. h is a comma-separated list that consists of one or more of the following: dir, no%dir, %all, %none, %user.
Table 5-2 The -errhdr Values
Value |
Meaning |
---|---|
dir |
Checks header files used in the directory dir |
no%dir |
Does not check header files used in the directory dir |
%all |
Checks all used header files |
%none |
Does not check header files. This is the default. |
%user |
Checks all used user header files, that is, all header files except those in /usr/include and its subdirectories, as well as those supplied by the compiler |
The default is -errhdr=%none. Specifying -errhdr is equivalent to specifying -errhdr=%user.
Examples:
% lint -errhdr=inc1 -errhdr=../inc2
checks used header files in directories inc1 and ../inc2.
% lint -errhdr=%all,no%../inc
checks all used header files except those in the directory ../inc.
Suppresses or enables lint error messages.
t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none.
Table 5-3 The -erroff Values
Value |
Meaning |
---|---|
tag |
Suppresses the message specified by this tag. You can display the tag for a message by using the -errtags=yes option. |
no%tag |
Enables the message specified by this tag |
%all |
Suppresses all messages |
%none |
Enables all messages. This is the default. |
The default is -erroff=%none. Specifying -erroff is equivalent to specifying -erroff=%all.
Examples:
% lint -erroff=%all,no%E_ENUM_NEVER_DEF,no%E_STATIC_UNUSED
prints only the messages "enum never defined" and "static unused", and suppresses other messages.
% lint -erroff=E_ENUM_NEVER_DEF,E_STATIC_UNUSED
suppresses only the messages "enum never defined" and "static unused".
Displays the message tag for each error message. a can be either yes or no. The default is -errtags=no. Specifying -errtags is equivalent to specifying -errtags=yes.
Works with all -errfmt options.
Prints the path names as supplied on the command line rather than only their base names when referring to the .c files named on the command line.
Reports about old-style function definitions or declarations.
Executes lint with options contained in the file file. Multiple options can be specified in file, one per line.
Suppresses certain messages. Refer to Table 5-5.
Searches the directory dir for included header files.
Alter the behavior of /* LINTED [message] */ directives or NOTE(LINTED(message)) annotations. Normally, lint suppresses warning messages for the code following these directives. Instead of suppressing the messages, lint prints an additional message containing the comment inside the directive or annotation.
Searches for a lint library in the directory dir when used with -l.
Accesses the lint library llib-lx.ln.
Suppresses certain messages. Refer to Table 5-5.
Checks header files for corresponding declarations; checks macros. c is a comma-separated list of checks that consists of one or more of the following: macro, extern, %all, %none, no%macro, no%extern.
Table 5-4 The -Ncheck Values
Value |
Meaning |
---|---|
macro |
Checks for consistency of macro definitions across files |
extern |
Checks for one-to-one correspondence of declarations between source files and their associated header files (for example, for file1.c and file1.h). Ensure that there are neither extraneous nor missing extern declarations in a header file. |
%all |
Performs all of -Ncheck's checks |
%none |
Performs none of -Ncheck's checks. This is the default. |
no%macro |
Performs none of -Ncheck's macro checks |
no%extern |
Performs none of -Ncheck's extern checks |
The default is -Ncheck=%none. Specifying -Ncheck is equivalent to specifying -Ncheck=%all.
Values may be combined with a comma, for example, -Ncheck=extern,macro.
Example:
% lint -Ncheck=%all,no%macro
performs all checks except macro checks.
Specifies the level of analysis for reporting problems. This option allows you to control the amount of detected errors. The higher the level, the longer the verification time. n is a number: 1, 2, 3, or 4.The default is -Nevel=2. Specifying -Nlevel is equivalent to specifying -Nlevel=4.
Analyzes single procedures. Reports unconditional errors that occur on some program execution paths. Does not do global data and control flow analysis.
The default. Analyzes the whole program, including global data and control flow. Reports unconditional errors that occur on some program execution paths.
Analyzes the whole program, including constant propagation, cases when constants are used as actual arguments, as well as the analysis performed under -Nlevel=2.
Verification of a C program at this analysis level takes two to four times longer then at the preceding level. The extra time is required because lint assumes partial interpretation of the program by creating sets of possible values for program variables. These sets of variables are created on the basis of constants and conditional statements that contain constant operands available in the program. The sets form the basis for creating other sets (a form of constant propagation). Sets received as the result of the analysis are evaluated for correctness according to the following algorithm:
If a correct value exists among all possible values of an object, then that correct value is used as the basis for further propagation; otherwise an error is diagnosed.
Analyzes the whole program, and reports conditional errors that could occur when certain program execution paths are used, as well as the analysis performed under -Nlevel=3.
At this analysis level, there are additional diagnostic messages. The analysis algorithm generally corresponds to the analysis algorithm of -Nlevel=3 with the exception that any invalid values now generate an error message. The amount of time required for analysis at this level can increase as much as two orders (about 20 to 100 time more slowly). In this case the extra time required is directly proportional to the program complexity as characterized by recursion, conditional statements etc. As a result of this, it may be difficult to use this level of analysis for a program that exceeds 100,000 lines.
Suppresses checks for compatibility with the default lint standard C library.
Causes lint to create a lint library with the name llib-lx.ln. This library is created from all the .ln files that lint used in its second pass. The -c option nullifies any use of the -o option. To produce a llib-lx.ln without extraneous messages, you can use the -x option. The -v option is useful if the source file(s) for the lint library are just external interfaces. The lint library produced can be used later if lint is invoked with -lx.
By default, you create libraries in lint's basic format. If you use lint's enhanced mode, the library created will be in enhanced format, and can only be used in enhanced mode.
Enables certain messages relating to portability issues.
Write a .ln file to file, for use by cxref(1). This option disables the enhanced mode, if it is switched on.
Converts compound messages into simple ones.
Suppresses certain messages. Refer to Table 5-5. This option is suitable for running lint on a subset of files of a larger program.
Writes the product name and releases to standard error.
Suppresses certain messages. Refer to Table 5-5.
Write a .ln file to file, for use by cflow(1). This option disables the enhanced mode, if it is switched on.
Suppresses certain messages. Refer to Table 5-5.
Accepts C++-style comments. In particular, // can be used to indicate the start of a comment. a can be either yes or no. The default is -XCC=no. Specifying -XCC is equivalent to specifying -XCC=yes.
Predefines the _ _sparcv9 macro and searches for v9 versions of lint libraries.
(SPARC) Directs lint to recognize #pragma MP directives. a can be either yes or no. The default is -Xexplicitpar=no. Specifying -Xexplicitpar is equivalent to specifying -Xexplicitpar=yes.
Keeps temporary files created during linting instead of deleting them automatically. a can be either yes or no. The default is -Xkeeptmp=no. Specifying -Xkeeptmp is equivalent to specifying -Xkeeptmp=yes.
Sets the directory for temporary files to dir. Without this option, temporary files go into /tmp.
Reports the execution time for each lint pass. a can be either yes or no. The default is -Xtime=no. Specifying -Xtime is equivalent to specifying -Xtime=yes.
Issues warnings for the differences between K&R C and Sun ANSI/ISO C. a can be either yes or no. The default is -Xtransition=no. Specifying -Xtransition is equivalent to specifying -Xtransition=yes.
Treats every .c file named on the command line as if it begins with the directive /* LINTLIBRARY */ or the annotation NOTE(LINTLIBRARY). A lint library is normally created using the /* LINTLIBRARY */ directive or the NOTE(LINTLIBRARY) annotation.