NAME
lint — check
C-language programs (DEVELOPMENT, LEGACY)
SYNOPSIS
lint |
[-abcnpuxv] [-D
name=value]file ...][-I
directory][-L directory] [-o
x][-U name]
operand... |
DESCRIPTION
The lint utility cross-checks multiple
C-language source files and library definitions and reports potential
errors. Among the error conditions that are detected are:
- unreachable statements
- loops not entered at the top
- automatic variables declared and not used
- inconsistent declarations between files
- non-portable constructions
- logical expressions whose value is constant
- functions that return values in some places and not in others
- functions called with varying numbers or types of arguments
- functions whose values are not used or whose values are used when none are returned.
The lint utility takes
all the files with .c and .ln suffixes, and any additional lint libraries
specified by the -l operand, and processes them in
their command-line order. By default, lint appends
the standard C lint library to the end of the list of files. However, if the
-p option is used, the portable C lint library
(llib-port.ln)
if it exists, will be appended instead. When the -c
option is not used, lint checks this list of files
for mutual compatibility. When the -c option is
used, the .ln files and the lint libraries are ignored.
Certain conventional comments in the C source change the behaviour
of lint:
- /*NOTREACHED*/
- Stop comments about unreachable code at appropriate points.
- /*VARARGSn*/
- Suppress the usual checking for variable numbers of arguments in the following function declaration. The data types of the first n arguments are checked; a missing n is taken to be zero.
- /*ARGSUSED*/
- Suppress diagnostic messages about unused arguments in the next function.
- /*LINTLIBRARY*/
- Suppress, at the beginning of a file, diagnostic messages about unused
functions and function arguments in this file. This is equivalent to using
the
-vand-xoptions.
Other comments in the C source of the form:
/\*[[:upper:]][[:upper:][:digit:]]*\*/ (where the
form is expressed using the syntax of basic regular expressions, defined in
the XBD
specification, re(7) ) may be interpreted by
lint in implementation-dependent ways.
If the -c option is specified,
then for all pathname operands of the form
file. c the files:
$(basename pathname .c).ln are produced.
If the -o option is present with
option-argument x, a file with the name:
llib-l$(basename x).ln is produced.
The lint utility produces its first output
on a per-source-file basis. Diagnostic messages regarding input files are
collected and printed after all source files have been processed. Finally,
if the -c option is not used, information gathered
from all input files is collected and checked for consistency. At this
point, if it is not clear whether a diagnostic message stems from a given
source file or from one of its included files, the source filename will be
printed followed by a question mark.
During the execution of lint, values are
established for certain predefined macros from the ISO C standard: __LINE__,
__FILE__, __DATE__, __TIME__ and __STDC__.
OPTIONS
The lint utility supports the XBD
specification,
Utility
Syntax Guidelines , except that the -l
operands have the format of options, but their position within a list of
operands affects the order in which libraries are searched.
The following options are supported:
- -a
- Suppress diagnostic messages about assignments of long values to variables that are not long.
- -b
- Suppress diagnostic messages about break statements that cannot be reached.
- -c
- Produce a .ln file for every .c file on the command line. These .ln files are not checked for interfunction compatibility.
- -h
- Do not apply heuristic tests that attempt to diagnose bugs intuitively, improve style and reduce waste.
- -n
- Do not check compatibility against either the standard or the portable lint library.
- -o x
- Produce a lint library with the name:
The
llib-l$(basename x).ln.
-coption nullifies any use of the-ooption. The-ooption causes this file to be saved in the named lint library. To produce the lint library without extraneous messages, the-xoption should be used. The-voption is useful if the source files for the lint library are just external interfaces. These option settings are also available through the use of the "lint comments" listed in the DESCRIPTION section. - -p
- Cause all non-external names to be treated as if they were truncated to thirty-one characters and all external names truncated to six characters, folded to one case. Append the portable C lint library, if it exists, to the end of the list of files.
- -u
- Suppress diagnostic messages about functions and external variables used
and not defined, or defined and not used. (This option is suitable for
running
linton a subset of files of a larger program.) - -v
- Suppress diagnostic messages about unused arguments in functions.
- -x
- Do not report variables referred to by external declarations but never used.
The -D,
-U, -L and
-I options of the C compiler (see
cc and
c89) are also
recognised as separate arguments.
The -g and -O
options of the C compiler are also recognised as separate arguments, but are
ignored. (By recognising these options, the behaviour of
lint is closer to that of the cc
utility.) Other options are ignored, and a warning message may be issued.
The pre-defined macro lint (for common-usage C) or __LINT__ (for the ISO C
standard) is defined to allow certain questionable code to be altered or
removed for lint.
OPERANDS
The following operands are supported:
- file.c
- A pathname naming a C-language source file.
- file.ln
- A pathname of a file analogous to a .o file produced by the C compiler.
An operand of the form -l
x means search the library named
llib-l x .ln or
llib-l x if llib-l
x .ln is not readable.
The processing of other files is implementation-dependent.
The lint utility will recognise the
following -l operands for standard libraries:
- -l c
- Names the Standard C library, llib-lc.ln , which will contain everything else defined by the ISO C standard. The library searched also will include all functions defined by the XSH specification. This operand is not required to be present to cause a search of the Standard C library.
- -l l
- Names the library llib-ll.ln , which will contain functions required by the C-language output of lex(1) that are not available through the Standard C library.
- -l m
- Names the library llib-lm.ln , which contains the functions described by the ISO C standard with prototypes in the <math.h> header.
- -l pthread
- Names the library llib-lpthread.ln , which contains the functions declared in <pthread.h> and pthread_atfork(3) referenced in <unistd.h> .
- -l rt
- Names the library llib-lrt.ln , which contains the functions described by the Realtime Feature Group.
- -l y
- Names the library llib-ly.ln , which contains functions required by the C-language output of yacc(1) that are not available through the Standard C library.
It is unspecified whether the libraries
llib-lc.ln,
llib-ll.ln,
llib-lm.ln,
llib-lpthread.ln,
llib-lrt.ln,
or
llib-ly.ln
(or any other library accessed via -l) exist as
regular files.
STDIN
Not used.
INPUT FILES
The input file must be one of the following: a .c suffixed text
file containing C-language source or a .ln suffixed file of unspecified
format produced by a previous invocation of lint
with a -c or -o option.
ENVIRONMENT VARIABLES
The following environment variables may affect the execution of
lint :
LANG- Provide a default value for the internationalisation variables that are
unset or null. If
LANGis unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL- If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
LC_MESSAGES- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH- Determine the location of message catalogues for the processing of LC_MESSAGES .
ASYNCHRONOUS EVENTS
Default.
STDOUT
The format of the report produced by lint
is unspecified.
STDERR
Used only for diagnostic and warning messages.
OUTPUT FILES
The format of .ln files is unspecified.
EXTENDED DESCRIPTION
The lint utility supports the same
programming environments specified in , EXTENDED DESCRIPTION. The default
programming environment supported by lint will be
the same as the default programming environment supported by
c89(1) . To use lint to
cross-check C-language source files and library definitions for other
supported programming environments, provide the corresponding
lint flags as the first options on the
lint command line.
Programming Environment getconf Name Corresponding lint Arguments getconf Name _XBS5_ILP32_OFF32 XBS5_ILP32_OFF32_LINTFLAGS _XBS5_ILP32_OFFBIG XBS5_ILP32_OFFBIG_LINTFLAGS _XBS5_LP64_OFF64 XBS5_LP64_OFF64_LINTFLAGS _XBS5_LPBIG_OFFBIG XBS5_LPBIG_OFFBIG_LINTFLAGS
Table: Programming Environments - lint Flags
EXIT STATUS
The following exit values are returned:
CONSEQUENCES OF ERRORS
Default.
APPLICATION USAGE
The behaviour of the -c and the
-o options allows for incremental use of
lint on a set of C source files. Generally,
lint is invoked once for each source file with the
-c option. Each of these invocations produces a .ln
file that corresponds to the .c file, and prints all messages that pertain
to 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 -l x options. This will print all the
interfile inconsistencies. This scheme works well with
make(1) ; it allows make(1) to be used
to lint only the source files that have been modified since the last time
the set of source files were checked by lint . If
used incrementally on a set of files, the result of partial checks can be
saved to speed subsequent intermodule consistency checks.
The lint library often contains all routines in that library stripped of everything but prototypes.
The intent of allowing unrecognised suffixes is to permit implementations to recognise things like archives and source of other languages, but not require all implementations to do so. Portable applications should use only the suffixes described in this specification.
Programs produced by
lex or
yacc will
often result in many diagnostic messages about
break
statements that cannot be reached. Use of -b is
recommended.
EXAMPLES
Assuming a file hierarchy as shown here:
$ ls -R libsrc: applib1.c applib2.c applib3.c applib.a appsrc: app1.c app2.c $ cd libsrc
The following creates
llib-applib.ln
for later use: $ lint -o applib applib*.c $ cd
../appsrc
The following checks the source for both applications against the
previously created library: $ for app in *.c > do >
lint -L ../libsrc $app -l applib > done
If the application source and libraries in the previous
example had all been built in the _XBS5_LP64_OFF64 programming model, the
for loop in the last
example would be changed to: $ LFLAGS=$(getconf
XBS5_LP64_OFF64_LINTFLAGS) $ for app in *.c > do > lint $LFLAGS -L
../libsrc $app -l applib > done
FUTURE DIRECTIONS
None.