LINT(1)

NAME
lint - a C program checker

SYNOPSIS
lint [ -abhuvx -KR -ansi ] [file | libname | -lxxx ] ...
lint -Llibname [ file | libname2 | -lxxx ] ...

DESCRIPTION
Lint does an extensive consistency and plausibility check on a set of C program files. When it detects a doubtful construction (which need not be an error) it gives a warning.

It does a full flow-of-control check, except that gotos are not followed and that the fact that a function never returns is not propagated. If, however, no gotos are used, each call of a non-returning function is followed by /*NOTREACHED*/ and each switch has a default clause (possibly consisting of /*NOTREACHED*/), the initialization state of all local variables will be checked correctly.

Lint checks the types of the arguments implied by the format in a call of printf(), scanf() and family, if the format string is a direct argument in the call. Formats of user functions can be indicated using a FORMAT pseudo-comment; see below.

Libraries

The second command (using the -L-option) is used to maintain lint libraries; these are ASCII files that contain the output of the first pass. A library name ends in .llb. A lint user library can be created and updated by using the -L option. The libname end in .llb, and can be passed to lint again as a normal argument.

Standard libraries are searched by default or by explicitly giving the -l option; their format is identical to that of the user library files. Possibilities are -lm, -ltermcap and -lcurses. -lc is default; a single -l tells lint not to use the standard C library. The standard libraries are searched for in the standard lint directory or in the directory given in the environment variable LINTLIB, if present.

Options

The -D, -U and -I options are recognized as separate arguments and conform to those of cc. The -KR option tells lint to check strictly according to Kernighan & Ritchie; since lint is trying to be helpful rather than obnoxious, this is not the default. The -ansi option tells lint to check according to ANSI C.

Lint understands the following additional options:

a   Warn about conversions that may cause a loss of precision.

b   Do not report not-reachable break statements. This flag may be useful when lint is run on a generated source file.

h   Apply several heuristics: signal "null effects", possible pointer alignment problems and odd constructs; report definitions of variables that have a scope wider than necessary: extern variables that are used in one file only, automatic variables that could be more local.

u   Do not complain about unused and undefined functions and global variables.

v   Do not warn about unused arguments of functions.

x   Complain about unused external variables.

Pseudo-comments

The following pseudo-comments can be used to influence the behaviour of lint:

/* ARGSUSED */
    Do not warn about arguments not used in the next function (see also the -v option).

/* NOTREACHED */
    This tells lint that the flow of control "cannot reach" this comment. This is a way to tell lint that a statement never "returns".

/* LINTLIBRARY */
    The definitions following this pseudo-comment are assumed to be part of a library. It suppresses complaints about unused functions and variables and is used in the creation of lint libraries. It implies /* ARGSUSED */.

/* VARARGSn */
    The next function can be called with a variable number of arguments. Only check the types of the first n arguments. The n must follow the word VARARGS immediately. /* VARARGS0 */ may be abbreviated to /* VARARGS */.

/* FORMATn $ ... $ */
    The n-th argument (counting from 0) of the next function declaration corresponds to a printf-like format string. Details about the format are given between the $$; see below. A missing $$ repeats the latest format. The n must follow the word FORMAT immediately. /* FORMATn $ ... $ */ implies /* VARARGSn+1 */; if the format is followed by more required arguments, a separate /* VARARGSm */ must be given after the FORMAT pseudo-comment.

    If the printf-like heading also has to conform to some varargs.h convention, error messages may result; these can be suppressed by appending the letter v to the word FORMATn without intervening space.

Formats

The $$-part of the FORMAT pseudo-comment consists of a list of format specifications, each of the form %T=type, where T is an arbitrary (short) string and type is the expected type in "C normal form" (like in a cast, with no superfluous parentheses and without the use of typedefs). E.g., %ld=long indicates that the format string ld corresponds to a parameter of type long. For a shorter notation see the example below. Lint recognizes conversion specifications of the form %[N|*|][.[N|*]]T where N is a number, the * is itself and T is a string as defined above. For the above example this would include %ld, %5.2ld, %.*ld, etc.

Example: the FORMAT pseudo-comment for printf() is:
/* FORMAT0 $
    %[dox] = int    %l[dox] = long    %[DOX] = long
    %u = unsigned int    %lu = unsigned long    %U = unsigned long
    %[feg] = double
    %c = int    %s = char *
$ */

Output

Some users feel it is a good idea to pipe the output of lint through the command
    sort -t' ' +0d -1 +2n -3
where the character between the apostrophes is a space.

ENVIRONMENT VARIABLES
LINTFLAGS    additional flag arguments (e.g. LINTFLAGS=-h)
LINTLIB    directory in which the standard libraries are looked up

FILES

???/lnt
    first pass

???/lpass2/lpass2
    second pass

???/llib/*.llb
    lint libraries

SEE ALSO
cem(1)
Frans Kunst, Lint, a C Program Checker

BUGS
Conflicting options in the command line are not detected.
After a label, all automatic variables are assumed initialized.

AUTHOR
Frans Kunst, Vrije Universiteit, Amsterdam.
Dick Grune, Vrije Universiteit, Amsterdam.