Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ lint(1) — OSF1 1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

make(1)

lint(1)  —  Commands

NAME

lint - Checks C programs for potential problems

SYNOPSIS

lint [-abchnpsuvx] [-D name[ =definition]] [-I directory] [-l key] [-o library] [-MA]
[-U name] [-w class ...] [file ...] The lint command checks C language source code for coding and syntax errors and for inefficient or nonportable code. 

FLAGS

-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 program to produce a .ln file for every .c file on the command line. These .ln files are the product of the first pass of the lint program only and are not checked for interfunction compatibility. 

-h Does not try to detect bugs, improper style, or reduce waste. 

-lkey Includes the additional library llib-lkey.ln.  You can include a version of the math library llib-lm.ln by specifying -lm on the command line.  Use this flag to include local libraries when checking files that are part of a project having a large number of files. This flag does not prevent lint from using the llib-lc.ln library. The library must be in the /usr/ccs/lib directory. 

-MA Enforces ANSI C Standard rules. The default mode is extended C mode. 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. 

-n Suppresses the check for compatibility with either the standard or the portable lint libraries. This applies for both ANSI and extended mode libraries. 

-o library
Causes the lint program to create a library with the name llib-llibrary.ln. The -c flag nullifies any use of the -o flag. The library produced is the input that is given to the second pass of the lint program. 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 file llib-lc is written). These flag settings are also available through the use of lint comment lines. 

-p Checks for portability to other C dialects. 

-s Checks for structure, union and pointer alignments that may be non-portable. 

-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. 

-w class [class...]
Controls the reporting of warning classes. All warning classes are active by default, but may be individually activated by including the appropriate option as part of the class argument. The individual options are listed as:

a Non-ANSI features

c Comparisons with unsigned values

d Declaration consistency

h Heuristic complaints

k Suppresses the 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 Deactivate all warnings

C Constants occurring in conditionals

D External declarations are never used

O Obsolescent features

P Function prototype presence

R Detection of unreachable code

S Storage capacity checks

-x Suppresses messages about variables that have external declarations but are never used. 

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

-Idirectory
Adds directory to the list of directories in which the lint program searches for the #include files. 

-Dname[=definition]
Defines the name, as if by #define. The default definition is 1. 

-Uname
Removes any initial definition of name, where name is a reserved symbol that is predefined by the particular preprocessor. 

DESCRIPTION

You can use lint to do the following:

•Identify source code and library incompatibility. 

•Enforce type checking rules more often, and in some cases, more strictly than the compiler. 

•Identify potential problems with variables. 

•Identify potential problems with functions. 

•Identify problems with flow control. 

•Identify legal constructions that may produce errors or be inefficient. 

•Identify unused variable and function declarations. 

•Identify possibly nonportable code. 

The interfile 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 filename extensions as follows:

•Filenames ending in .c are C Language source files

•Filenames ending in .ln are nontext files that lint produces when either the -c or the -o flag is used.  The lint command warns you about files with other suffixes and ignores them. 

The lint command takes all the .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 lint library (llib-lc.ln) to the end of the list of files. However, when you select the -p flag, the lint command uses the portable library llib-port.ln.  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 lib-lx files are ignored. 

The -c and -o flags allow for incremental use of the lint program on a set of 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 program, run it once more, without the -c flag, listing all the .ln files with the needed -l arguments. This writes all interfile 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 following comments in a C source program change the way that lint operates when checking the source program:

/∗NOTREACHED∗/
Suppresses comments about unreachable code.

/∗VARARGSn∗/
Suppresses checking the following old style function declaration for varying numbers of arguments, but does check the data type of the first n arguments. If you do not include a value for n, lint checks no arguments (n=0). 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, lint 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 prototypes declarations appear as function definitions. This directive implicitly activates both /∗NOTUSED∗/ and /∗LINTLIBRARY∗/ to reduce warning noise levels. 

If you have not specified the -c flag, the lint program 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 filename followed by a ? (question mark). 

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

EXAMPLES

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

lint program.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 standard lint library (/usr/ccs/lib/llib-lc.ln) and /usr/ccs/lib/llib-lsubs.ln. 

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

lint -lsubs -p program.c

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

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

lint -lsubs -n program.c

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

FILES

/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-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).

/var/tmp/∗lint∗
Temporary files.

RELATED INFORMATION

Commands: make(1). 

The as, gcc (cc), gdb, and ld commands are not provided with OSF/1.  The as, cc, and ld commands are provided with the HP OSF/1 Technology Release. 

COMPATIBILITY WITH OSF/1

The −s option is provided with the HP OSF/1 Technology Release.  It may not be provided on other implementations of OSF/1. 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026