1 .\" $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $
3 .\" Copyright (c) 1994, 1995 Jochen Pohl
4 .\" All Rights Reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by Jochen Pohl for
17 .\" The NetBSD Project.
18 .\" 4. The name of the author may not be used to endorse or promote products
19 .\" derived from this software without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 .\" $FreeBSD: src/usr.bin/xlint/xlint/lint.1,v 1.8.2.7 2002/06/21 15:30:23 charnier Exp $
33 .\" $DragonFly: src/usr.bin/xlint/xlint/lint.1,v 1.2 2003/06/17 04:29:34 dillon Exp $
40 .Nd a C program verifier
47 .Op Fl D Ar name Ns Op = Ns Ar def
52 .Op Fl o Ar outputfile
58 .Op Fl D Ar name Ns Op = Ns Ar def
66 utility attempts to detect features of the named C program files
67 that are likely to be bugs, to be non-portable, or to be
69 It also performs stricter type checking than
73 utility runs the C preprocessor as its first phase, with the
76 defined to allow certain questionable code to be altered
79 Therefore, this symbol should be thought of as a reserved
80 word for all code that is to be checked by
83 Among the possible problems that are currently noted are
84 unreachable statements, loops not entered at the top,
85 variables declared and not used, and logical expressions
87 Function calls are checked for
88 inconsistencies, such as calls to functions that return
89 values in some places and not in others, functions called
90 with varying numbers of arguments, function calls that
91 pass arguments of a type other than the type the function
92 expects to receive, functions whose values are not used,
93 and calls to functions not returning values that use
94 the non-existent return value of the function.
96 Filename arguments ending with
98 are taken to be C source files.
99 Filename arguments with
102 are taken to be the result of an earlier invocation of
111 files are analogous to the
113 (object) files produced by
120 utility also accepts special libraries specified with the
122 option, which contain definitions of library routines and
127 utility takes all the
130 .Pa llib-l Ns Ar library Ns Pa .ln
131 (lint library) files and processes them in command-line order.
134 appends the standard C lint library
136 to the end of the list of files.
146 options are used, the
147 .Pa llib-l Ns Ar library Ns Pa .ln
155 checks this list of files for mutual compatibility.
157 if a complaint stems not from a given source file, but from one of
158 its included files, the source filename will be printed followed by
161 The options are as follows:
162 .Bl -tag -width indent
164 Report assignments of
166 values to variables that are not
173 assignments of integer values to other integer values which
174 cause implicit narrowing conversion.
178 statements that cannot be reached.
179 This is not the default
180 because, unfortunately, most
184 outputs produce many such complaints.
186 Complain about casts which have questionable portability.
188 Complain about unusual operations on
193 .Vt int Ns eger-Types .
195 Don't print warnings for some extensions of
198 Currently these are nonconstant initializers in
199 automatic aggregate initializations, arithmetic on pointer to void,
200 zero sized structures, subscripting of non-lvalue arrays, prototypes
201 overriding old style function declarations and long long
205 flag also turns on the keywords
209 (alternate keywords with leading underscores for both
213 are always available).
215 Apply a number of heuristic tests to attempt to intuit
216 bugs, improve style, and reduce waste.
222 file on the command line.
225 files are the product of
227 first pass only, and are not checked for compatibility
230 Do not check compatibility against the standard library.
232 Attempt to check portability of code to other dialects of C.
234 In case of redeclarations report the position of the
235 previous declaration.
238 Issue warnings and errors required by ANSI C.
239 Also do not produce warnings for constructs which behave
240 differently in traditional C and ANSI C.
245 is a predefined preprocessor macro.
249 is not predefined in this mode.
250 Warnings are printed for constructs
251 not allowed in traditional C.
252 Warnings for constructs which behave
253 differently in traditional C and ANSI C are suppressed.
255 macros describing the machine type (e.g.,
257 and machine architecture (e.g.,
259 are defined without leading and trailing underscores.
264 are not available in traditional C mode (although the alternate
265 keywords with leading underscores still are).
267 Do not complain about functions and external variables used
268 and not defined, or defined and not used (this is suitable
271 on a subset of files comprising part of a larger program).
273 Suppress complaints about unused arguments in functions.
275 Report variables referred to by
277 declarations, but never used.
279 Do not complain about structures that are never defined
280 (for example, using a structure pointer without knowing
285 library with the name
286 .Pa llib-l Ns Ar library Ns Pa .ln .
287 This library is built from all
292 After all global definitions of functions and
293 variables in these files are written to the newly created library,
295 checks all input files, including libraries specified with the
297 option, for mutual compatibility.
298 .It Fl D Ar name Ns Op = Ns Ar def
306 If no definition is given,
309 .It Fl I Ar directory
312 to the list of directories in which to search for include files.
314 Include the lint library
315 .Pa llib-l Ns Ar library Ns Pa .ln .
316 .It Fl L Ar directory
317 Search for lint libraries in
320 .Ar directory Ns Pa /lint
321 before searching the standard place.
323 Print pathnames of files.
326 utility normally prints the filename without the path.
328 If a complaint stems from an included file
330 prints the name of the included file instead of the source file name
331 followed by a question mark.
332 .It Fl o Ar outputfile
335 The output file produced is the input that is given to
340 option simply saves this file in the named output file.
343 option is also used the files are not checked for compatibility.
345 .Pa llib-l Ns Ar library Ns Pa .ln
346 without extraneous messages, use of the
351 option is useful if the source file(s) for the lint library
352 are just external interfaces.
354 Remove any initial definition of
356 for the preprocessor.
358 Print the command lines constructed by the controller program to
359 run the C preprocessor and
361 first and second pass.
365 first pass reads standard C source files.
368 utility recognizes the following C comments as commands.
369 .Bl -tag -width indent
370 .It Li /* ARGSUSED Ns Ar n Li */
375 arguments for usage; a missing
377 is taken to be 0 (this option acts like the
379 option for the next function).
383 .Li /* CONSTANTCOND */
385 .Li /* CONSTANTCONDITION */
387 suppress complaints about constant operands for the next expression.
391 .Li /* FALLTHROUGH */
393 suppress complaints about fall through to a
398 This directive should be placed immediately
400 .It Li /* LINTLIBRARY */
401 At the beginning of a file, mark all functions and variables defined
404 Also shut off complaints about unused function arguments.
406 .Li /* LINTED Oo Ar comment Oc Li */
408 .Li /* NOSTRICT Oo Ar comment Oc Li */
410 Suppresses any intra-file warning except those dealing with
411 unused variables or functions.
412 This directive should be placed
413 on the line immediately preceding where the
416 .It Li /* LONGLONG */
417 Suppress complaints about use of long long integer types.
418 .It Li /* NOTREACHED */
419 At appropriate points, inhibit complaints about unreachable code.
420 (This comment is typically placed just after calls to functions
423 .It Li /* PRINTFLIKE Ns Ar n Li */
431 argument is interpreted as a
433 format string that is used to check the remaining arguments.
434 .It Li /* PROTOLIB Ns Ar n Li */
437 to treat function declaration prototypes as function definitions
441 This directive can only be used in conjunction with
443 .Li /* LINTLIBRARY */
447 is zero, function prototypes will be treated normally.
448 .It Li /* SCANFLIKE Ns Ar n Li */
456 argument is interpreted as a
458 format string that is used to check the remaining arguments.
459 .It Li /* VARARGS Ns Ar n Li */
460 Suppress the usual checking for variable numbers of arguments in
461 the following function declaration.
462 The data types of the first
464 arguments are checked; a missing
473 options allows for incremental use of
475 on a set of C source files.
476 Generally, one invokes
478 once for each source file with the
481 Each of these invocations produces a
483 file that corresponds to the
485 file, and prints all messages that are about just that
487 After all the source files have been separately
490 it is invoked once more (without the
492 option), listing all the
494 files with the needed
497 This will print all the inter-file inconsistencies.
499 scheme works well with
505 only the source files that have been modified since the last
506 time the set of source files were
509 .Bl -tag -width LIBDIR
511 the directory where the lint libraries specified by the
516 If this environment variable is undefined,
517 then the default path
518 .Pa /usr/libdata/lint
519 will be used to search for the libraries.
521 usually the path for temporary files can be redefined by setting
522 this environment variable.
525 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
526 .It Pa /usr/libexec/lint Ns Bq Pa 12
528 .It Pa /usr/libdata/lint/llib-l*.ln
529 various prebuilt lint libraries
545 and other functions that do not return are not understood; this
546 causes various incorrect diagnostics.
548 Static functions which are used only before their first
549 extern declaration are reported as unused.
551 Libraries created by the
553 option will, when used in later
555 runs, cause certain errors that were reported when the libraries
556 were created to be reported again, and cause line numbers and file
557 names from the original source used to create those libraries
558 to be reported in error messages.
559 For these reasons, it is recommended
562 option to create lint libraries.