[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 3

lint Command


Checks C and C++ language programs for potential problems.


lint [ -a ] [ -b ] [ -c ] [ -C ] [ -h ] [ -lKey ] [ -n ] [ -oLibrary ] [ -qDBCS ] [ -p ] [ -t ] [ -u ] [ -v ] [ -w Class [Class ... ] ] [ -x ] [ -MA ] [ -NdNumber ] [ -NlNumber ] [ -NnNumber ] [ -NtNumber ] [ -IDirectory ] [ -DName [=Definition ] ] [ -UName ] File ...


The lint command checks C and C++ language source code for coding and syntax errors and for inefficient or non-portable code. You can use this program to:

The inter-file usage of functions is checked to find functions that return values in some instances and not in others, functions called with varying numbers or types of arguments, and functions whose values are not used or whose values are used but not returned.

The lint command interprets file name extensions as follows:

The lint command warns you about files with other suffixes and ignores them.

The lint command takes all the .c, .C, and .ln files and the libraries specified by -l flags and processes them in the order that they appear on the command line. By default, it adds the standard llib-lc.ln lint library to the end of the list of files. However, when you select the -p flag, the lint command uses the llib-port.ln portable library. By default, the second pass of lint checks this list of files for mutual compatibility; however, if you specify the -c flag, the .ln and llib-lx.ln files are ignored.

The -c and -o flags allow for incremental use of the lint command on a set of C and C++ language source files. Generally, use the lint command once for each source file with the -c flag. Each of these runs produces a .ln file that corresponds to the .c file and writes all messages concerning that source file. After you have run all source files separately through the lint command, run it once more, without the -c flag, listing all the .ln files with the needed -l flags. This writes all inter-file inconsistencies. This procedure works well with the make command, allowing it to run the lint command on only those source files modified since the last time that set of source files was checked.

The lint and LINT preprocessor symbols are defined to allow certain questionable code to be altered or removed for the lint command. Therefore, the lint and LINT symbols should be thought of as a reserved word for all code that is planned to be checked by lint.

The following comments in a C and C++ language source program change the way the lint command operates when checking the source program:

/*NOTREACHED*/ Suppresses comments about unreachable code.
/*VARARGSNumber*/ Suppresses checking the following old style function declaration for varying numbers of arguments, but does check the data type of the first Number arguments. If you do not include a value for Number, the lint command checks no arguments (Number=0). The ANSI function prototypes should use the ellipsis to indicate unspecified parameters rather than this comment mechanism.
/*ARGSUSED*/ Suppresses warnings about function parameters not used within the function definition.
/*LINTLIBRARY*/ If you place this comment at the beginning of a file, the lint command does not identify unused functions and function parameters in the file. This is used when running the lint command on libraries.
/*NOTUSED*/ Suppresses warnings about unused external symbols, functions and function parameters in the file beginning at its point of occurrence. This is a superset of the /*LINTLIBRARY*/ comment directive, but applies also to external symbols. It is useful for suppressing warnings about unused function prototypes and other external object declarations.
/*NOTDEFINED*/ Suppresses warnings about used, but undefined external symbols and functions in the file beginning at its point of occurrence.
/*LINTSTDLIB*/ Permits a standard prototype-checking library to be formed from header files by making function prototype declarations appear as function definitions. This directive implicitly activates both the /*NOTUSED*/ and /*LINTLIBRARY*/ comment directives to reduce warning noise levels.

The lint command warning messages give file name and line number. As each file goes through the first pass, warnings for each file and each line number are reported.

If you have not specified the -c flag, the lint command collects information gathered from all input files and checks it for consistency. At this point, if it is not clear whether a message stems from a given source file or from one of its included files, the lint command displays the source file name followed by a question mark.

ANSI programs that include many standard header files may wish to set the -wD flag to reduce the quantity of warnings about prototypes not used, and the -n flag to disable checking against the ANSI standard library. For non-ANSI programs, it is advisable to specify the -wk flag to reduce the amount of warnings concerning the absence of function prototypes.


-a Suppresses messages about assignments of long values to variables that are not long.
-b Suppresses messages about unreachable break statements.
-c Causes the lint command to produce an .ln file for every .c file on the command line. These .ln files are the product of the first pass of the lint command only and are not checked for inter-function compatibility.
-C Specifies to use the C++ libraries (in the /usr/lpp//xlC/lib directory).
-h Does not try to detect bugs, improper style, or reduce waste.
-lKey Includes the additional llib-lKey.ln lint library. You can include a lint version of the llib-lm.ln math library by specifying -lm on the command line or llib-ldos.ln library by specifying the -ldos flag on the command line. Use this flag to include local lint libraries when checking files that are part of a project having a large number of files. This flag does not prevent the lint command from using the llib-lc.ln library. The lint library must be in the /usr/ccs/lib directory.
-n Suppresses the check for compatibility with either the standard or the portable lint libraries. This applies for both the ANSI and extended mode libraries.
-oLibrary Causes the lint command to create the llib-lLibrary.ln lint library. The -c flag nullifies any use of the -o flag. The lint library produced is the input that is given to the second pass of the lint command. The -o flag simply causes this file to be saved in the named lint library. To produce a llib-lLibrary.ln without extraneous messages, use the -x flag. The -v flag is useful if the source files for the lint library are just external interfaces (for example, the way the llib-lc file is written). These flag settings are also available through the use of lint command comment lines.
-p Checks for portability to other C language dialects.
-t Checks for problematic assignments when porting from 32 to 64 bit. Only the following cases are checked:
  • all shift / mask operations are flagged because some operations that work well in 32-bit may cause problems in 64-bit.
  • warnings are given for the following type of assignments.

    int = long
    int = ptr
-u Suppresses messages about functions and external variables that are either used and not defined or defined and not used. Use this flag to run the lint command on a subset of files of a larger program.
-v Suppresses messages about function parameters that are not used.
-wClass[Class...] Controls the reporting of warning classes. All warning classes are active by default, but can be individually deactivated by including the appropriate option as part of the Class argument. The individual options are listed as:

Non-ANSI features.

Comparisons with unsigned values.

Declaration consistency.

Heuristic complaints.

Use for K+R type source code.

Assignment of long values to variables that are not long.

Null-effect code.

Unknown order of evaluation.

Various portability concerns.

Return statement consistency.

Storage capacity checks.

Proper usage of variables and functions.

Deactivate all warnings.

Constants occurring in conditionals.

External declarations are never used.

Obsolescent features.

Function prototype presence.

Detection of unreachable code.
-x Suppresses messages about variables that have external declarations but are never used.
-MA Enforces the ANSI C language standard rules. The default mode is equal to the extended C mode. The ANSI mode prepends the standard ANSI library function prototypes in place of the default extended mode C lint library. The ANSI mode enforces a stricter inter-file object reference and provides definition linkage checks.
-NdNumber Changes the dimension table size to Number. The default value of Number is 2000.
-NlNumber Changes the number of type nodes to Number. The default value of Number is 8000.
-NnNumber Increases the size of the symbol table to Number. The default value of Number is 1500.
-NtNumber Changes the number of tree nodes to Number. The default value of Number is 1000.

In addition, the lint command recognizes the following flags of the cpp command (macro preprocessor):

-IDirectory Adds the Directory to the list of directories in which the lint command searches for the #include files.
-DName[=Definition] Defines the Name, as if by the #define file. The default of the Definition is the value of 1.
-qDBCS Sets multibyte mode specified by the current locale.
-UName Removes any initial definition of the Name, where the Name is a reserved symbol that is predefined by the particular preprocessor.

Exit Status

This command returns the following exit values:

0 Successful completion.
>0 An error occurred.


  1. To check a C program for errors, enter:

    lint command.c
  2. To suppress some of the messages, enter:

    lint -v -x program.c

    This checks program.c, but does not display error messages about unused function parameters (-v) or unused externals (-x).

  3. To check the program against an additional lint library, enter:

    lint -lsubs program.c

    This checks program.c against both the /usr/ccs/lib/llib-lc.ln standard lint library and /usr/lib/llib-lsubs.ln lint library.

  4. To check against the portable library and an additional library, enter:

    lint -lsubs -p program.c

    This checks program.c against both the /usr/ccs/lib/llib-port.ln portable lint library and /usr/lib/llib-lsubs.ln lint library.

  5. To check against a nonstandard library only, enter:

    lint -lsubs -n program.c

    This checks program.c against only /usr/lib/llib-lsubs.ln.


/usr/lib/lint[12} Programs
/usr/ccs/lib/llib-lansi Declarations for standard ANSI functions (source)
/usr/ccs/lib/llib-lansi.ln Declarations for standard ANSI functions (binary format)
/usr/ccs/lib/llib-lc Declarations for standard functions (source)
/usr/ccs/lib/llib-lc.ln Declarations for standard functions (binary format)
/usr/ccs/lib/llib-lcrses Declarations for curses functions (source)
/usr/ccs/lib/llib-lcrses.ln Declarations for curses functions (binary format)
/usr/ccs/lib/llib-lm Declarations for standard math functions (source)
/usr/ccs/lib/llib-lm.ln Declarations for standard math functions (binary format)
/usr/ccs/lib/llib-port Declarations for portable functions (source)
/usr/ccs/lib/llib-port.ln Declarations for portable functions (binary format)
/usr/lpp//xlC/lib Directory containing C++ libraries
/var/tmp/*lint* Temporary files

Related Information

The cpp command, make command.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]