1 .\" $NetBSD: lint.1,v 1.29 2004/01/26 21:59:42 wiz Exp $
3 .\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
4 .\" Copyright (c) 1994, 1995 Jochen Pohl
5 .\" All Rights Reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by Jochen Pohl for
18 .\" The NetBSD Project.
19 .\" 4. The name of the author may not be used to endorse or promote products
20 .\" derived from this software without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 .Nd a C program verifier
44 .Op Fl abceghprvwxzHFV
47 .Op Fl D Ar name Ns Op = Ns Ar def
54 .Op Fl o Ar outputfile
56 .Op Fl X Ar id Ns Op , Ns Ar id ...
62 .Op Fl D Ar name Ns Op = Ns Ar def
67 .Op Fl X Ar id Ns Op , Ns Ar id ...
73 utility attempts to detect features of the named C program files
74 that are likely to be bugs, to be non-portable, or to be
76 It also performs stricter type checking than does
80 utility runs the C preprocessor as its first phase, with the
83 defined to allow certain questionable code to be altered
86 Therefore, this symbol should be thought of as a reserved
87 word for all code that is to be checked by
90 Among the possible problems that are currently noted are
91 unreachable statements, loops not entered at the top,
92 variables declared and not used, and logical expressions
94 Function calls are checked for
95 inconsistencies, such as calls to functions that return
96 values in some places and not in others, functions called
97 with varying numbers of arguments, function calls that
98 pass arguments of a type other than the type the function
99 expects to receive, functions whose values are not used,
100 and calls to functions not returning values that use
101 the non-existent return value of the function.
103 Filename arguments ending with
105 are taken to be C source files.
106 Filename arguments with
109 are taken to be the result of an earlier invocation of
118 files are analogous to the
120 (object) files produced by
127 utility also accepts special libraries specified with the
129 option, which contain definitions of library routines and
134 utility takes all the
137 .Pa llib-l Ns Ar library Ns Pa .ln
138 (lint library) files and processes them in command-line order.
141 appends the standard C lint library
143 to the end of the list of files.
153 options are used, the
154 .Pa llib-l Ns Ar library Ns Pa .ln
162 checks this list of files for mutual compatibility.
164 if a complaint stems not from a given source file, but from one of
165 its included files, the source filename will be printed followed by
168 The special input file name
172 to take input from standard input (until end of file) and process
180 is named as one of the input files, the
182 flag must also be specified to provide an output file name.
183 The options are as follows:
184 .Bl -tag -width indent
186 Report assignments of
188 values to variables that are not
195 assignments of integer values to other integer values which
196 cause implicit narrowing conversion.
200 statements that cannot be reached.
201 This is not the default
202 because, unfortunately, most
206 outputs produce many such complaints.
208 Complain about casts which have questionable portability.
210 Complain about unusual operations on
215 .Sy integer Ns -Types .
217 Do not print warnings for some extensions of
220 Currently these are nonconstant initializers in
221 automatic aggregate initializations, arithmetic on pointer to void,
224 declarations, C++ -style
227 zero sized structures, subscripting of non-lvalue arrays, prototypes
228 overriding old style function declarations and long long
232 flag also turns on the keywords
236 (alternative keywords with leading underscores for both
240 are always available).
242 Apply a number of heuristic tests to attempt to intuit
243 bugs, improve style, and reduce waste.
249 file on the command line.
252 files are the product of
254 first pass only, and are not checked for compatibility
257 Do not check compatibility against the standard library.
259 Attempt to check portability of code to other dialects of C.
261 In case of redeclarations report the position of the
262 previous declaration.
265 Issue warnings and errors required by ANSI C.
266 Also do not produce warnings for constructs which behave
267 differently in traditional C and ANSI C.
272 is a predefined preprocessor macro.
274 C9X mode. Currently not fully implemented.
278 is not predefined in this mode.
279 Warnings are printed for constructs
280 not allowed in traditional C.
281 Warnings for constructs which behave
282 differently in traditional C and ANSI C are suppressed.
284 macros describing the machine type (e.g.,
286 and machine architecture (e.g.,
288 are defined without leading and trailing underscores.
293 are not available in traditional C mode (although the alternative
294 keywords with leading underscores still are).
296 Do not complain about functions and external variables used
297 and not defined, or defined and not used (this is suitable
300 on a subset of files comprising part of a larger program).
302 Suppress complaints about unused arguments in functions.
304 Report variables referred to by
306 declarations, but never used.
308 Do not complain about structures that are never defined
309 (for example, using a structure pointer without knowing
312 Path to use when looking for the
322 library with the name
323 .Pa llib-l Ns Ar library Ns Pa .ln .
324 This library is built from all
329 After all global definitions of functions and
330 variables in these files are written to the newly created library,
332 checks all input files, including libraries specified with the
334 option, for mutual compatibility.
335 .It Fl D Ar name Ns Op = Ns Ar def
343 If no definition is given,
346 .It Fl I Ar directory
349 to the list of directories in which to search for include files.
350 .It Fl d Ar directory
355 as the default place to find include files.
357 Include the lint library
358 .Pa llib-l Ns Ar library Ns Pa .ln .
359 .It Fl L Ar directory
360 Search for lint libraries in
363 .Ar directory Ns Pa /lint
364 before searching the standard place.
366 Print pathnames of files.
369 utility normally prints the filename without the path.
371 If a complaint stems from an included file
373 prints the name of the included file instead of the source file name
374 followed by a question mark.
380 causing cpp to create files containing dependency information for
382 .It Fl o Ar outputfile
385 The output file produced is the input that is given to
390 option simply saves this file in the named output file.
393 option is also used the files are not checked for compatibility.
395 .Pa llib-l Ns Ar library Ns Pa .ln
396 without extraneous messages, use of the
401 option is useful if the source file(s) for the lint library
402 are just external interfaces.
404 Remove any initial definition of
406 for the preprocessor.
408 Print the command lines constructed by the controller program to
409 run the C preprocessor and
411 first and second pass.
413 Treat warnings as errors.
414 .It Fl X Ar id Ns Op , Ns Ar id ...
415 Suppress error messages identified by the list of ids.
417 and ids can be found in
422 first pass reads standard C source files.
425 utility recognizes the following C comments as commands.
426 .Bl -tag -width indent
427 .It Li /* ARGSUSED Ns Ar n Li */
432 arguments for usage; a missing
434 is taken to be 0 (this option acts like the
436 option for the next function).
437 .It Li /* BITFIELDTYPE */
438 Suppress error messages about illegal bitfield types if the type
439 is an integer type, and suppress non-portable bitfield type warnings.
443 .Li /* CONSTANTCOND */
445 .Li /* CONSTANTCONDITION */
447 suppress complaints about constant operands for the next expression.
451 .Li /* FALLTHROUGH */
453 suppress complaints about fall through to a
458 This directive should be placed immediately
460 .It Li /* LINTLIBRARY */
461 At the beginning of a file, mark all functions and variables defined
464 Also shut off complaints about unused function arguments.
466 .Li /* LINTED Oo Ar comment Oc Li */
468 .Li /* NOSTRICT Oo Ar comment Oc Li */
470 Suppresses any intra-file warning except those dealing with
471 unused variables or functions.
472 This directive should be placed
473 on the line immediately preceding where the
476 .It Li /* LONGLONG */
477 Suppress complaints about use of long long integer types.
478 .It Li /* NOTREACHED */
479 At appropriate points, inhibit complaints about unreachable code.
480 (This comment is typically placed just after calls to functions
483 .It Li /* PRINTFLIKE Ns Ar n Li */
491 argument is interpreted as a
493 format string that is used to check the remaining arguments.
494 .It Li /* PROTOLIB Ns Ar n Li */
497 to treat function declaration prototypes as function definitions
501 This directive can only be used in conjunction with
503 .Li /* LINTLIBRARY */
507 is zero, function prototypes will be treated normally.
508 .It Li /* SCANFLIKE Ns Ar n Li */
516 argument is interpreted as a
518 format string that is used to check the remaining arguments.
519 .It Li /* VARARGS Ns Ar n Li */
520 Suppress the usual checking for variable numbers of arguments in
521 the following function declaration.
522 The data types of the first
524 arguments are checked; a missing
533 options allows for incremental use of
535 on a set of C source files.
536 Generally, one invokes
538 once for each source file with the
541 Each of these invocations produces a
543 file that corresponds to the
545 file, and prints all messages that are about just that
547 After all the source files have been separately
550 it is invoked once more (without the
552 option), listing all the
554 files with the needed
557 This will print all the inter-file inconsistencies.
559 scheme works well with
565 only the source files that have been modified since the last
566 time the set of source files were
569 .Bl -tag -width LIBDIR
571 the directory where the lint libraries specified by the
576 If this environment variable is undefined,
577 then the default path
578 .Pa /usr/libdata/lint
579 will be used to search for the libraries.
581 usually the path for temporary files can be redefined by setting
582 this environment variable.
584 Location of the C compiler program.
589 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
590 .It Pa /usr/libexec/lint Ns Bq Pa 12
592 .It Pa /usr/libdata/lint/llib-l*.ln
593 various prebuilt lint libraries
609 and other functions that do not return are not understood; this
610 causes various incorrect diagnostics.
612 Static functions which are used only before their first
613 extern declaration are reported as unused.
615 Libraries created by the
617 option will, when used in later
619 runs, cause certain errors that were reported when the libraries
620 were created to be reported again, and cause line numbers and file
621 names from the original source used to create those libraries
622 to be reported in error messages.
623 For these reasons, it is recommended
626 option to create lint libraries.