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 $
39 .Nd a C program verifier
46 .Op Fl D Ar name Ns Op = Ns Ar def
51 .Op Fl o Ar outputfile
57 .Op Fl D Ar name Ns Op = Ns Ar def
65 utility attempts to detect features of the named C program files
66 that are likely to be bugs, to be non-portable, or to be
68 It also performs stricter type checking than
72 utility runs the C preprocessor as its first phase, with the
75 defined to allow certain questionable code to be altered
78 Therefore, this symbol should be thought of as a reserved
79 word for all code that is to be checked by
82 Among the possible problems that are currently noted are
83 unreachable statements, loops not entered at the top,
84 variables declared and not used, and logical expressions
86 Function calls are checked for
87 inconsistencies, such as calls to functions that return
88 values in some places and not in others, functions called
89 with varying numbers of arguments, function calls that
90 pass arguments of a type other than the type the function
91 expects to receive, functions whose values are not used,
92 and calls to functions not returning values that use
93 the non-existent return value of the function.
95 Filename arguments ending with
97 are taken to be C source files.
98 Filename arguments with
101 are taken to be the result of an earlier invocation of
110 files are analogous to the
112 (object) files produced by
119 utility also accepts special libraries specified with the
121 option, which contain definitions of library routines and
126 utility takes all the
129 .Pa llib-l Ns Ar library Ns Pa .ln
130 (lint library) files and processes them in command-line order.
133 appends the standard C lint library
135 to the end of the list of files.
145 options are used, the
146 .Pa llib-l Ns Ar library Ns Pa .ln
154 checks this list of files for mutual compatibility.
156 if a complaint stems not from a given source file, but from one of
157 its included files, the source filename will be printed followed by
160 The options are as follows:
161 .Bl -tag -width indent
163 Report assignments of
165 values to variables that are not
172 assignments of integer values to other integer values which
173 cause implicit narrowing conversion.
177 statements that cannot be reached.
178 This is not the default
179 because, unfortunately, most
183 outputs produce many such complaints.
185 Complain about casts which have questionable portability.
187 Complain about unusual operations on
192 .Vt int Ns eger-Types .
194 Don't print warnings for some extensions of
197 Currently these are nonconstant initializers in
198 automatic aggregate initializations, arithmetic on pointer to void,
199 zero sized structures, subscripting of non-lvalue arrays, prototypes
200 overriding old style function declarations and long long
204 flag also turns on the keywords
208 (alternate keywords with leading underscores for both
212 are always available).
214 Apply a number of heuristic tests to attempt to intuit
215 bugs, improve style, and reduce waste.
221 file on the command line.
224 files are the product of
226 first pass only, and are not checked for compatibility
229 Do not check compatibility against the standard library.
231 Attempt to check portability of code to other dialects of C.
233 In case of redeclarations report the position of the
234 previous declaration.
237 Issue warnings and errors required by ANSI C.
238 Also do not produce warnings for constructs which behave
239 differently in traditional C and ANSI C.
244 is a predefined preprocessor macro.
248 is not predefined in this mode.
249 Warnings are printed for constructs
250 not allowed in traditional C.
251 Warnings for constructs which behave
252 differently in traditional C and ANSI C are suppressed.
254 macros describing the machine type (e.g.,
256 and machine architecture (e.g.,
258 are defined without leading and trailing underscores.
263 are not available in traditional C mode (although the alternate
264 keywords with leading underscores still are).
266 Do not complain about functions and external variables used
267 and not defined, or defined and not used (this is suitable
270 on a subset of files comprising part of a larger program).
272 Suppress complaints about unused arguments in functions.
274 Report variables referred to by
276 declarations, but never used.
278 Do not complain about structures that are never defined
279 (for example, using a structure pointer without knowing
284 library with the name
285 .Pa llib-l Ns Ar library Ns Pa .ln .
286 This library is built from all
291 After all global definitions of functions and
292 variables in these files are written to the newly created library,
294 checks all input files, including libraries specified with the
296 option, for mutual compatibility.
297 .It Fl D Ar name Ns Op = Ns Ar def
305 If no definition is given,
308 .It Fl I Ar directory
311 to the list of directories in which to search for include files.
313 Include the lint library
314 .Pa llib-l Ns Ar library Ns Pa .ln .
315 .It Fl L Ar directory
316 Search for lint libraries in
319 .Ar directory Ns Pa /lint
320 before searching the standard place.
322 Print pathnames of files.
325 utility normally prints the filename without the path.
327 If a complaint stems from an included file
329 prints the name of the included file instead of the source file name
330 followed by a question mark.
331 .It Fl o Ar outputfile
334 The output file produced is the input that is given to
339 option simply saves this file in the named output file.
342 option is also used the files are not checked for compatibility.
344 .Pa llib-l Ns Ar library Ns Pa .ln
345 without extraneous messages, use of the
350 option is useful if the source file(s) for the lint library
351 are just external interfaces.
353 Remove any initial definition of
355 for the preprocessor.
357 Print the command lines constructed by the controller program to
358 run the C preprocessor and
360 first and second pass.
364 first pass reads standard C source files.
367 utility recognizes the following C comments as commands.
368 .Bl -tag -width indent
369 .It Li /* ARGSUSED Ns Ar n Li */
374 arguments for usage; a missing
376 is taken to be 0 (this option acts like the
378 option for the next function).
382 .Li /* CONSTANTCOND */
384 .Li /* CONSTANTCONDITION */
386 suppress complaints about constant operands for the next expression.
390 .Li /* FALLTHROUGH */
392 suppress complaints about fall through to a
397 This directive should be placed immediately
399 .It Li /* LINTLIBRARY */
400 At the beginning of a file, mark all functions and variables defined
403 Also shut off complaints about unused function arguments.
405 .Li /* LINTED Oo Ar comment Oc Li */
407 .Li /* NOSTRICT Oo Ar comment Oc Li */
409 Suppresses any intra-file warning except those dealing with
410 unused variables or functions.
411 This directive should be placed
412 on the line immediately preceding where the
415 .It Li /* LONGLONG */
416 Suppress complaints about use of long long integer types.
417 .It Li /* NOTREACHED */
418 At appropriate points, inhibit complaints about unreachable code.
419 (This comment is typically placed just after calls to functions
422 .It Li /* PRINTFLIKE Ns Ar n Li */
430 argument is interpreted as a
432 format string that is used to check the remaining arguments.
433 .It Li /* PROTOLIB Ns Ar n Li */
436 to treat function declaration prototypes as function definitions
440 This directive can only be used in conjunction with
442 .Li /* LINTLIBRARY */
446 is zero, function prototypes will be treated normally.
447 .It Li /* SCANFLIKE Ns Ar n Li */
455 argument is interpreted as a
457 format string that is used to check the remaining arguments.
458 .It Li /* VARARGS Ns Ar n Li */
459 Suppress the usual checking for variable numbers of arguments in
460 the following function declaration.
461 The data types of the first
463 arguments are checked; a missing
472 options allows for incremental use of
474 on a set of C source files.
475 Generally, one invokes
477 once for each source file with the
480 Each of these invocations produces a
482 file that corresponds to the
484 file, and prints all messages that are about just that
486 After all the source files have been separately
489 it is invoked once more (without the
491 option), listing all the
493 files with the needed
496 This will print all the inter-file inconsistencies.
498 scheme works well with
504 only the source files that have been modified since the last
505 time the set of source files were
508 .Bl -tag -width LIBDIR
510 the directory where the lint libraries specified by the
515 If this environment variable is undefined,
516 then the default path
517 .Pa /usr/libdata/lint
518 will be used to search for the libraries.
520 usually the path for temporary files can be redefined by setting
521 this environment variable.
524 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
525 .It Pa /usr/libexec/lint Ns Bq Pa 12
527 .It Pa /usr/libdata/lint/llib-l*.ln
528 various prebuilt lint libraries
544 and other functions that do not return are not understood; this
545 causes various incorrect diagnostics.
547 Static functions which are used only before their first
548 extern declaration are reported as unused.
550 Libraries created by the
552 option will, when used in later
554 runs, cause certain errors that were reported when the libraries
555 were created to be reported again, and cause line numbers and file
556 names from the original source used to create those libraries
557 to be reported in error messages.
558 For these reasons, it is recommended
561 option to create lint libraries.