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.3 2004/07/07 07:37:04 asmodai Exp $
40 .Nd a C program verifier
44 .Op Fl abceghprvxzHFSV
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.
247 C9X mode. Currently not fully implemented.
251 is not predefined in this mode.
252 Warnings are printed for constructs
253 not allowed in traditional C.
254 Warnings for constructs which behave
255 differently in traditional C and ANSI C are suppressed.
257 macros describing the machine type (e.g.,
259 and machine architecture (e.g.,
261 are defined without leading and trailing underscores.
266 are not available in traditional C mode (although the alternate
267 keywords with leading underscores still are).
269 Do not complain about functions and external variables used
270 and not defined, or defined and not used (this is suitable
273 on a subset of files comprising part of a larger program).
275 Suppress complaints about unused arguments in functions.
277 Report variables referred to by
279 declarations, but never used.
281 Do not complain about structures that are never defined
282 (for example, using a structure pointer without knowing
287 library with the name
288 .Pa llib-l Ns Ar library Ns Pa .ln .
289 This library is built from all
294 After all global definitions of functions and
295 variables in these files are written to the newly created library,
297 checks all input files, including libraries specified with the
299 option, for mutual compatibility.
300 .It Fl D Ar name Ns Op = Ns Ar def
308 If no definition is given,
311 .It Fl I Ar directory
314 to the list of directories in which to search for include files.
316 Include the lint library
317 .Pa llib-l Ns Ar library Ns Pa .ln .
318 .It Fl L Ar directory
319 Search for lint libraries in
322 .Ar directory Ns Pa /lint
323 before searching the standard place.
325 Print pathnames of files.
328 utility normally prints the filename without the path.
330 If a complaint stems from an included file
332 prints the name of the included file instead of the source file name
333 followed by a question mark.
334 .It Fl o Ar outputfile
337 The output file produced is the input that is given to
342 option simply saves this file in the named output file.
345 option is also used the files are not checked for compatibility.
347 .Pa llib-l Ns Ar library Ns Pa .ln
348 without extraneous messages, use of the
353 option is useful if the source file(s) for the lint library
354 are just external interfaces.
356 Remove any initial definition of
358 for the preprocessor.
360 Print the command lines constructed by the controller program to
361 run the C preprocessor and
363 first and second pass.
367 first pass reads standard C source files.
370 utility recognizes the following C comments as commands.
371 .Bl -tag -width indent
372 .It Li /* ARGSUSED Ns Ar n Li */
377 arguments for usage; a missing
379 is taken to be 0 (this option acts like the
381 option for the next function).
385 .Li /* CONSTANTCOND */
387 .Li /* CONSTANTCONDITION */
389 suppress complaints about constant operands for the next expression.
393 .Li /* FALLTHROUGH */
395 suppress complaints about fall through to a
400 This directive should be placed immediately
402 .It Li /* LINTLIBRARY */
403 At the beginning of a file, mark all functions and variables defined
406 Also shut off complaints about unused function arguments.
408 .Li /* LINTED Oo Ar comment Oc Li */
410 .Li /* NOSTRICT Oo Ar comment Oc Li */
412 Suppresses any intra-file warning except those dealing with
413 unused variables or functions.
414 This directive should be placed
415 on the line immediately preceding where the
418 .It Li /* LONGLONG */
419 Suppress complaints about use of long long integer types.
420 .It Li /* NOTREACHED */
421 At appropriate points, inhibit complaints about unreachable code.
422 (This comment is typically placed just after calls to functions
425 .It Li /* PRINTFLIKE Ns Ar n Li */
433 argument is interpreted as a
435 format string that is used to check the remaining arguments.
436 .It Li /* PROTOLIB Ns Ar n Li */
439 to treat function declaration prototypes as function definitions
443 This directive can only be used in conjunction with
445 .Li /* LINTLIBRARY */
449 is zero, function prototypes will be treated normally.
450 .It Li /* SCANFLIKE Ns Ar n Li */
458 argument is interpreted as a
460 format string that is used to check the remaining arguments.
461 .It Li /* VARARGS Ns Ar n Li */
462 Suppress the usual checking for variable numbers of arguments in
463 the following function declaration.
464 The data types of the first
466 arguments are checked; a missing
475 options allows for incremental use of
477 on a set of C source files.
478 Generally, one invokes
480 once for each source file with the
483 Each of these invocations produces a
485 file that corresponds to the
487 file, and prints all messages that are about just that
489 After all the source files have been separately
492 it is invoked once more (without the
494 option), listing all the
496 files with the needed
499 This will print all the inter-file inconsistencies.
501 scheme works well with
507 only the source files that have been modified since the last
508 time the set of source files were
511 .Bl -tag -width LIBDIR
513 the directory where the lint libraries specified by the
518 If this environment variable is undefined,
519 then the default path
520 .Pa /usr/libdata/lint
521 will be used to search for the libraries.
523 usually the path for temporary files can be redefined by setting
524 this environment variable.
527 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
528 .It Pa /usr/libexec/lint Ns Bq Pa 12
530 .It Pa /usr/libdata/lint/llib-l*.ln
531 various prebuilt lint libraries
547 and other functions that do not return are not understood; this
548 causes various incorrect diagnostics.
550 Static functions which are used only before their first
551 extern declaration are reported as unused.
553 Libraries created by the
555 option will, when used in later
557 runs, cause certain errors that were reported when the libraries
558 were created to be reported again, and cause line numbers and file
559 names from the original source used to create those libraries
560 to be reported in error messages.
561 For these reasons, it is recommended
564 option to create lint libraries.