lint - a C program checker
lint [-abchlnpuvx] [-Xdollar] [-wclass...] [-cpp] [-lx] [-olib] [-dpath]
[-MA] [-Msuboptions] [-Pppoptions] [-stdn] [-XEnum] [-Qsuboptions] [-Ndnum]
[-Nlnum] [-Nnnum] [-Ntnum] [-Dname[=definition]] [-Idirectory] [-Uname]
Any number of lint options may be used, in any order, intermixed with
file-name arguments. The following options are used to suppress certain
kinds of complaints:
-a Suppress complaints about assignments of long values to variables that
are not long.
-b Suppress complaints about break statements that cannot be reached.
(Programs produced by lex or yacc will often result in many such com-
-h Do not apply heuristic tests that attempt to intuit bugs, improve
style, and reduce waste.
-u Suppress complaints about functions and external variables used and not
defined, or defined and not used. (This option is suitable for running
lint on a subset of files of a larger program).
-v Suppress complaints about unused arguments in functions.
-x Do not report variables referred to by external declarations but never
Suppress complaints about the use of the dollar sign ($) in variable
Controls the reporting of warning classes. All warning classes are
active by default. They can however, be individually activated by
including the appropriate option as part of the class argument. For
example, to report only declaration consistency and Heuristic com-
plaints, enter the following command:
lint -wA -wdh prog.c
In the preceding example, -wA deactivates all warnings and -wdh
activates the desired reports. The following list describes available
classes of warnings:
a Non-ANSI features
c Comparisons with unsigned values
d Declaration consistency
h Heuristic complaints
k Suppresses the following messages: function prototype not in scope
and old style argument declaration.
l Assignment of long values to variables that are not long
n Null-effect code
o Unknown order of evaluation
p Various portability concerns
r Return statement consistency
u Proper usage of variables and functions
A Deactivates all warnings
C Constants occurring in conditionals
D Declarations that are never used or defined.
O Obsolete features
P Function prototype presence
R Detection of unreachable code
S Storage capacity checks
U Equivalent to -u
The following options alter lint's behavior:
Cause lint to use /lib/cpp as its preprocessor instead of /usr/bin/cc.
-lx Include additional lint library llib-lx.ln. For example, you can
include a lint version of the Math Library llib-lm.ln by inserting -lm
on the command line. This argument does not suppress the default use
of llib-lc.ln. These lint libraries must be in the assumed directory.
This option can be used to reference local lint libraries and is useful
in the development of multi-file projects. To conform to the UNIX98
standard, a space character can be inserted between the -l and the
library identifier, x (for example you can specify -l m to include a
lint version of the Math Library).
-n Do not check compatibility against either the standard or the portable
-1 Do not check compatibility between files or the lint libraries.
-p Attempt to check portability to other dialects (IBM and GCOS) of C.
Along with stricter checking, this option causes all non-external names
to be truncated to eight characters and all external names to be trun-
cated to six characters and one case.
-c Cause lint to produce a .ln file for every .c file on the command line.
These .ln files are the product of lint's first pass only, and are not
checked for inter-function compatibility.
Cause lint to create a lint library with the name llib-llib.ln. The -c
option nullifies any use of the -o option. The lint library produced is
the input that is given to lint's second pass. The -o option simply
causes this file to be saved in the named lint library. To produce a
llib-llib.ln without extraneous messages, use of the -x option is sug-
gested. The -v option is useful if the source file(s) for the lint
library are just external interfaces (for example, the way the file
llib-lc is written). These option settings are also available through
the use of "lint comments" (see below).
Cause lint to store the files created as a result of the -o or -c
option in the specified path.
-MA Enforce ANSI C standard rules. The default lint preprocessing and
parsing mode is Extended C (K&R). ANSI mode prepends (adds at the
beginning) the standard ANSI library function prototypes in place of
the default extended-mode C library. ANSI mode enforces a stricter
interfile object reference/definition linkage checking. This option
also invokes the -std1 C preprocessor option and defines the macro
Turn on or off specific ANSI features. The following suboptions are
a follow ANSI parsing rules
b follow ANSI const array struct member bug
c follow ANSI type compatibility rules
p follow ANSI type promotion rules
r follow ANSI strict reference/definition rules
s follow ANSI scoping rules for externs
t follow ANSI typing rules
The following rules govern the effects of the -M option:
+ If A is specified in a single instance of a -M option (-MA), the
checking for all of the suboptions is turned on.
+ If any of the suboptions are specified in a single instance of a
-M option when A is also specified (-MAsuboptions), the checking
for the specified suboptions is turned off.
+ If any of the suboptions are specified twice in all instances of
the -M option, they cancel each other out.
+ If suboptions are specified in a single instance of a -M option
and A is not specified (-Msuboptions), the checking for only the
specified suboptions is turned on.
For example, -MAt turns on all ANSI rules except ANSI typing rules.
Allows C preprocessor options to be specified when executing the lint
command. For example, specifying -PV invokes the preprocessor with the
-V option specified.
Directs the C Preprocessor to generate the appropriate predefined mac-
ros. The -std option causes the macro __STDC__=0 to be passed to the
preprocessor; -std1 causes the macro __STDC__=1 to be passed, and -std0
causes __STDC__ to be undefined. The default is -std0. The -std0 option
is incompatible with the -M option. If -std or -std1 are selected, the
-MA ANSI parsing rules are automatically selected.
Specifies the number (num) of errors lint accepts before terminating.
By default, lint terminates after encountering 30 errors.
The -Q option turns on checking for all common programming techniques which
might cause problems when moving from 32-bit systems to 64-bit systems. The
-Q option disables checking for other programming problems, so this switch
should be used only for migration checking.
Suboptions to -Q have the form -Qsuboptions. You can enter more than one
suboption with the -Q option, for example, -QacP to suppress checking for
pointer alignment problems, problematic type casts, and function prototype
The following suboptions are available to suppress specific categories of
a Suppresses checking of pointer alignment problems.
c Suppresses checking for problematic type casts. (Overrides -QG option.)
f Suppresses checking for format control strings in scanf and printf.
l Suppresses checking for assignments of long values to variables of a
type other than long.
p Suppresses checking for illegal combinations pointer and integer data
s Suppresses checking for problematic sign extensions to long
u Suppresses checking to see if a variable is used before it is set.
C Suppresses checking to see if there is constant truncation of longs in
F Suppresses checking to see if precision has been lost in field assign-
G Suppresses truncation message when casting to char *. (Overridden by
P Suppresses function prototype checks.
S Suppresses checking for a problematic combination of structure
pointers. If structure checking and cast checking are not suppressed
then the casting of differing structures and pointers to structures are
flagged if the structures differ in size and/or alignment as described
in the following two suboptions.
z Suppresses warnings about casting a structure or structure pointer to
one of a different size. Takes effect only if c and S are not specified
on the command line.
g Suppresses warnings about casting a structure or structure pointer to
on of a different alignment. Takes effect only if c and S are not
specified on the command line.
The -N option and its related suboptions allow you to increase the size of
various internal tables at run time if the default values are not suffi-
cient. All of the tables are dynamically expandable; however, larger ini-
tial values may improve run-time performance.
Suboptions to the -N option take the form -Nzx where z is a suboption and x
is an integer size. The following suboptions are available:
Use with -N to increase the initial size of the symbol table. To
increase the number of entries, use -Nnnum to increase the number of
entries. Use a number greater than 1500, which is the default value.
The larger the number, the fewer collisions. As a rule of thumb, use a
number roughly twice the number of source code lines.
Use with -N when you encounter the error that the dimension table has
overflowed or is full. To increase the number of base elements allo-
cated to the members of the dimension tables, use a number greater than
2000, which is the default value.
Use with -N when you encounter the error stating that the parse tree
limit has been reached, "out of tree space; recompile with -Ntx option
with x greater than xxxx". Do not recompile; run lint again on the
module that generated the error using -Ntyyyy with yyyy greater than
the value in the error message.
Use with -N when you encounter the error stating that the local type
table limit has been reached, "out of tree space; recompile with -Nlx
option with x greater than xxxx". Run lint again, do not recompile, on
the module that generated the error, using -Nlyyyy with yyyy greater
than the value in the error message.
The -D, -I, and -U options of cpp and the -g and -O options of cc are also
recognized as separate arguments. The -g and -O options are ignored, but,
by recognizing these options, lint's behavior is closer to that of the cc
command. Other options are warned about and ignored. The preprocessor sym-
bol "lint" is defined to allow certain questionable code to be altered or
removed for lint. Therefore, the symbol "lint" should be thought of as a
reserved word for all code that is planned to be checked by lint.
The following lint directives, which appear as conventional comments in the
C source program, change the behavior of lint:
Prevents lint from warning against unused function arguments (that is,
turns on the -v option) for the next function.
When placed at the beginning of a file, suppresses complaints about
unused functions and function arguments in this file. This is
equivalent to using the -v and -x options. This directive is used for
building lint libraries.
Permits a standard prototype checking library to be formed from header
files by making function prototype declarations appear as function
definitions. The /*LINTSTDLIB*/ directive implicitly activates the
functions of the /*NOTUSED*/ and /*LINTLIBRARY*/ directives to reduce
warning noise levels.
When placed in a file, suppresses warnings about all used but undefined
external symbols and functions that are subsequently encountered in the
When placed at appropriate points in a program (typically immediately
following a return, break, or continue statement), stops comments about
unreachable code. Note that lint does not recognize the exit function
and other functions that may not return.
When placed in a file, suppresses warnings about all unused external
symbols, functions, and function parameters that are subsequently
encountered in the file. This directive is similar to the /*LINTLI-
BRARY*/ directive, although /*NOTUSED*/ also applies to external sym-
Suppresses the usual checking for variable numbers of arguments in the
following function declaration. The data types of the first n arguments
are checked; for instance, if /*VARARGS2*/ is specified, lint checks
only the first two arguments. If n is not specified, it is interpreted
as a 0 (zero).
The lint utility produces its first output on a per-source-file basis. Com-
plaints regarding included files are collected and printed after all source
files have been processed. Finally, if the -c option is not used, informa-
tion gathered from all input files is collected and checked for con-
sistency. At this point, if it is not clear whether a complaint stems from
a given source file or from one of its included files, the source file name
will be printed followed by a question mark.
The behavior of the -c and the -o options allows for incremental use of
lint on a set of C source files. Generally, one invokes lint once for each
source file with the -c option. Each of these invocations produces a .ln
file which corresponds to the .c file, and prints all messages that are
about just that source file. After all the source files have been
separately run through lint, it is invoked once more (without the -c
option), listing all the .ln files with the needed -lx options. This will
print all the inter-file inconsistencies. This scheme works well with
make(1); it allows make to be used to lint only the source files that have
been modified since the last time the set of source files were run through
The lint program checker attempts to detect features of the C program files
that are likely to be bugs, non-portable, or wasteful. It also checks type
usage more strictly than the compilers. Among the things that are currently
detected are unreachable statements, loops not entered at the top,
automatic variables declared and not used, and logical expressions whose
value is constant.
Moreover, the usage of functions is checked to find functions that return
values in some places 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 none returned.
Arguments whose names end with .c are taken to be C source files. Arguments
whose names end with .ln are taken to be the result of an earlier invoca-
tion of lint with either the -c or the -o option used. The .ln files are
analogous to .o (object) files that are produced by the cc command when
given a .c file as input. Files with other suffixes produce warnings and
The lint program checker will take all the .c, .ln, and llib-lx.ln (speci-
fied by -lx) files and process them in their command line order. It appends
a lint library file to this list of files, as follows:
+ If the -p option is used, the portable C lint library (llib-port.ln)
+ If the -std or -std1 option is used, the C standard lint library
llib-lcstd.ln) is appended.
+ If the -MA option is used, the ANSI standard lint library (llib-
lansi.ln) is appended.
+ Otherwise, the standard C lint library (llib-lc.ln) is appended.
When the -c option is not used, the second pass of lint checks this list of
files for mutual compatibility. When the -c option is used, the .ln and the
llib-lx.ln files are ignored.
The exit(2), setjmp(3), and other functions that do not return are not
understood; this causes various lies.
The directory where the lint libraries specified by the -lx option must
The directory where the lint library sources are kept.
First and second passes of lint.
Declarations for C library functions (binary format; source is in
Declarations for Curses library functions (binary format; source is in
Declarations for C library functions (binary format; source is in
llib-lc.c). This is the default library when the -std or -std1 command
line options are used with lint.
Declarations for LEX library functions (binary format; source is in
Declarations for Math library functions (binary format; source is in
Declarations for YACC library functions (binary format; source is in
Declarations for the POSIX thread library functions (binary format;
source is in llib-lpthread.c).
Declarations for the POSIX real-time extensions library functions
(binary format; source is in llib-lrt.c).
Declarations for portable functions (binary format; source is in llib-
Temporary files (default directory /usr/tmp).
Commands: cc(1), cpp(1), make(1)