Updated: 2022/Sep/29
Please read Privacy Policy. It's for your privacy.
LINT(1) General Commands Manual LINT(1) NAME lint - a C program verifier SYNOPSIS lint [-abceFgHhPprTVvwxz] [-i | -nu] [-S | -s | -t | -Ac11 | -Ac23] [-B directory] [-D name[=def]] [-d directory] [-I directory] [-L directory] [-MD] [-l library] [-o outputfile] [-q id[,id]...] [-U name] [-W cppwarnarg] [-X id[,id]...] [-Z cpparg] file ... lint [-abceFgHhprTVvwz] [-S | -s | -t | -Ac11 | -Ac23] -C library [-B directory] [-D name[=def]] [-d directory] [-I directory] [-MD] [-R old=new] [-U name] [-W cppwarnarg] [-X id[,id]...] [-Z cpparg] file ... DESCRIPTION lint attempts to detect features of the named C program files that are likely to be bugs, to be non-portable, or to be wasteful. It also performs stricter type checking than traditional pre-C90 C compilers. The list of errors and warnings that lint produces are enumerated in lint(7). In the first synopsis form, lint checks each given file as a separate translation unit. In the second synopsis form, lint cross-checks the results of the first synopsis form for inconsistencies between translation units. lint runs the C preprocessor as its first phase, with the following preprocessor symbols defined to allow certain questionable code to be altered or skipped: __LINT__, lint, __lint, __lint__. These symbols should therefore be thought of as reserved words for all code that is to be checked by lint. Among the possible problems that are currently noted are unreachable statements, loops not entered at the top, variables declared and not used, and logical expressions with constant values. Function calls are checked for inconsistencies, such as calls to functions that return values in some places and not in others, non-prototype functions called with varying numbers of arguments, non-prototype function calls that pass arguments of a type other than the type the function expects to receive, functions whose return values are not used, and calls to non-prototype functions not returning values that nevertheless use the non-existent return value of the function. Filename arguments ending with .c are taken to be C source files. Filename arguments with names ending with .ln are taken to be the result of an earlier invocation of lint, with either the -i, -o or -C option in effect. The .ln files are analogous to the .o (object) files produced by cc(1) from .c files. lint also accepts special libraries specified with the -l option, which contain definitions of library routines and variables. lint takes all the .c, .ln, and llib-llibrary.ln (lint library) files and processes them in command-line order. By default, lint appends the standard C lint library (llib-lc.ln) to the end of the list of files. When the -i option is used, the .ln files are ignored. Also, when the -o or -i options are used, the llib-llibrary.ln files are ignored. When the -i option is omitted, the second pass of lint checks this list of files for mutual compatibility but always exits successfully. At this point, if a complaint stems not from a given source file, but from one of its included files, the source filename will be printed followed by a question mark. Options -Ac11 Allow features from C11, C99 and C90. -Ac23 Allow features from C23, C17, C11, C99 and C90. -a Report assignments of long values to variables that are not long. -aa Additional to -a, report all assignments of integer values to other integer values which cause implicit narrowing conversion. -Bpath Path to use when looking for the lint1 and lint2 binaries. Defaults to /usr/libexec. -b Report break statements that cannot be reached. This is not the default because, unfortunately, most lex(1) and many yacc(1) outputs produce many such complaints. -Clibrary Create a lint library with the name llib-llibrary.ln. This library is built from all .c and .ln input files. After all global definitions of functions and variables in these files are written to the newly created library, lint checks all input files, including libraries specified with the -l option, for mutual compatibility. -c Complain about casts which have questionable portability. -Dname[=def] Define name for cpp(1), as if by a #define directive. If no definition is given, name is defined as 1. -ddirectory Use directory as the root directory (DESTDIR) to find include files. -e Complain about unusual operations on enum types and combinations of enum and integer types. -F Print pathnames of files, not only the basenames. lint normally prints the filename without the path. -g Don't print warnings for some extensions of gcc(1) to the C language. Currently these are nonconstant initializers in automatic aggregate initializations, arithmetic on pointer to void, trailing commas in enum declarations, C++ -style "//" comments, zero sized structures, subscripting of non- lvalue arrays, prototypes overriding old-style function declarations and long long integer types. The -g flag also turns on the keywords asm and inline (alternative keywords with leading underscores for both asm and inline are always available). -H If a complaint stems from an included file, print the name of the included file instead of the source file name followed by a question mark. -h Apply a number of heuristic tests to attempt to intuit bugs, improve style, and reduce waste. -Idirectory Add directory to the list of directories in which to search for include files. -i Produce a .ln file for every .c file on the command line. These .ln files are the product of lint's first pass only, and are not checked for compatibility between functions. -Ldirectory Search for lint libraries in directory and directory/lint before searching the standard place. -llibrary Include the lint library llib-llibrary.ln. -MD Pass -MD to cpp(1), causing cpp to create files containing dependency information for each source file. -n Do not check compatibility against the standard library. -ooutputfile Name the output file outputfile. The output file produced is the input that is given to lint's second pass. The -o option simply saves this file in the named output file. If the -i option is also used, the files are not checked for compatibility. To produce a llib-llibrary.ln without extraneous messages, use of the -u option is suggested. The -v option is useful if the source file(s) for the lint library are just external interfaces. -P Enable more portability warnings: enum comparisons, sign extension issues when assigning to wider integer types, overflow warnings when assigning to wider types. -p Attempt to check portability of code to other platforms of C. -q id[,id]... In addition to the usual warnings and errors, run the selected queries, which are listed in lint(7). These queries are similar to warnings, they do not highlight possible bugs though, but instead point to other events in the code that may be interesting to look at on a case-by- case basis. The most convenient way to run queries on a source file is to run: make LINT="lint -q3,5,7" source.ln To allow this command to be run repeatedly, the option -q prevents creating the .ln file. -R old=new Remap old directory prefixes to new for reproducible builds. -r In case of redeclarations, report the position of the previous declaration. -S C99 mode. Currently not fully implemented. -s Strict ISO C90 mode. Issue warnings and errors required by ISO C90, as opposed to traditional C. Also do not produce warnings for constructs which behave differently in traditional C and ISO C90. With the -s flag, __STRICT_ANSI__ is a predefined preprocessor macro. -T Treat _Bool as a data type that is incompatible with all other scalar types. -t Traditional C mode. __STDC__ is not predefined in this mode. Warnings are printed for constructs not allowed in traditional C. Warnings for constructs which behave differently in traditional C and C90 are suppressed. Preprocessor macros describing the machine type (e.g. sun3) and machine architecture (e.g. m68k) are defined without leading and trailing underscores. The keywords const, volatile and signed are not available in traditional C mode (although the alternative keywords with leading underscores still are). -Uname Remove any initial definition of name for the preprocessor. -u Do not complain about functions and external variables used and not defined, or defined and not used (this is suitable for running lint on a subset of files comprising part of a larger program). -V Print the command lines constructed by the controller program to run the C preprocessor and lint's first and second pass. -v Suppress complaints about unused parameters in functions. -W cppwarnarg Pass the warning directive to cpp(1). -w Treat warnings as errors. -X id[,id]... Suppress error messages identified by the list of ids. A list of messages and ids can be found in lint(7). -x Report variables referred to by extern declarations, but never used. -Z cpparg Pass cpparg to cpp(1) directly. Multiple -Z cppargs can be passed in the order they are received. -z Do not complain about structures that are never defined (for example, using a structure pointer without knowing its contents). Input Grammar lint's first pass reads standard C source files. lint recognizes the following C comments as commands. /* ARGSUSEDn */ Makes lint check only the first n parameters for usage; a missing n is taken to be 0 (this option acts like the -v option for the next function). /* BITFIELDTYPE */ Suppress error messages about illegal bitfield types if the type is an integer type, and suppress non-portable bitfield type warnings. /* CONSTCOND */ or /* CONSTANTCOND */ or /* CONSTANTCONDITION */ Suppress complaints about constant operands for the next expression. /* FALLTHRU */ or /* FALLTHROUGH */ Suppress complaints about fall through to a case or default labeled statement. This directive should be placed immediately preceding the label. /* LINTLIBRARY */ At the beginning of a file, mark all functions and variables defined in this file as used. Also shut off complaints about unused function parameters. /* LINTEDn [comment] */ or /* NOSTRICTn [comment] */ Suppresses any intra-file warning except those dealing with unused variables or functions. This directive should be placed on the line immediately preceding where the lint warning occurred. The optional numeric argument suppresses the specific numbered message instead of every message. A list of messages and ids can be found in lint(7). /* LONGLONG */ Suppress complaints about use of long long integer types. /* NOTREACHED */ At appropriate points, inhibit complaints about unreachable code. (This comment is typically placed just after calls to functions like exit(3)). /* PRINTFLIKEn */ Makes lint check the first (n-1) arguments as usual. The n-th argument is interpreted as a printf format string that is used to check the remaining arguments. /* PROTOLIBn */ Causes lint to treat function declaration prototypes as function definitions if n is non-zero. This directive can only be used in conjunction with the /* LINTLIBRARY */ directive. If n is zero, function prototypes will be treated normally. /* SCANFLIKEn */ Makes lint check the first (n-1) arguments as usual. The n-th argument is interpreted as a scanf format string that is used to check the remaining arguments. /* 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 0. The behavior of the -i and the -o options allows for incremental use of lint on a set of C source files. Generally, one invokes lint once for each source file with the -i option. Each of these invocations produces a .ln file that corresponds to the .c file, and prints all messages that are about just that source file. After all the source files have been separately run through lint, it is invoked once more (without the -i option), listing all the .ln files with the needed -llibrary options. This will print all the inter-file 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 linted. EXIT STATUS The lint utility exits 0 on success, and >0 if an error occurs. If the -w flag is given, warnings are considered errors. ENVIRONMENT LIBDIR The directory where the lint libraries specified by the -llibrary option must exist. If this environment variable is undefined, then the default path /usr/libdata/lint will be used to search for the libraries. LINT_KEEP_CPPOUT If set to `yes', or if set to `on-error' and lint exits unsuccessfully, do no delete the output from the C preprocessor, allowing for manual inspection. TMPDIR Usually the path for temporary files can be redefined by setting this environment variable. CC Location of the C compiler program. Defaults to /usr/bin/cc. FILES /usr/libexec/lint[12] programs /usr/libdata/lint/llib-l*.ln various prebuilt lint libraries /tmp/lint* temporaries EXAMPLES lint -i -Sg source.c Run lint in C99 mode with GNU extensions, with only few checks, creating source.ln. lint -i -abcFghprSxz source.c Run lint with the same checks as in the NetBSD build. lint -i -Ac11 -g -aabceFhpPrTxz source.c Run lint in C11 mode with GNU extensions, enabling all available checks, including lossy conversions on small integer types, unusual operations on enum types, more portability warnings, and strict bool mode. SEE ALSO cc(1), cpp(1), make(1), lint(7) AUTHORS Jochen Pohl (1995) Roland Illig (2021 to 2023) BUGS The routines exit(3), longjmp(3) and other functions that do not return are not understood; this causes various incorrect diagnostics. Static functions which are used only before their first extern declaration are reported as unused. Libraries created by the -o option will, when used in later lint runs, cause certain errors that were reported when the libraries were created to be reported again, and cause line numbers and file names from the original source used to create those libraries to be reported in error messages. For these reasons, it is recommended to use the -C option to create lint libraries. NetBSD 10.99 August 2, 2023 NetBSD 10.99