|
|
The lint(CP) analyzer checks for code constructs that may cause your C program not to compile, or to execute with unexpected results. lint issues the error and warning messages produced by the C compiler. It also issues ``lint-specific'' warnings about potential bugs and portability problems.
In particular, lint compensates for separate and independent compilation of files in C by flagging inconsistencies in definition and use across files, including any libraries you have used. In a large project environment especially, where the same function may be used by different programmers in hundreds of separate modules of code, lint can help discover bugs that otherwise might be difficult to find. A function called with one less argument than expected, for example, looks at the stack for a value the call has never pushed, with results correct in one condition, incorrect in another, depending on whatever happens to be in memory at that stack location. By identifying dependencies like this one, and dependencies on machine architecture as well, lint can improve the reliability of code run on your machine or someone else's.
lint is a static analyzer, which means that it cannot evaluate the run-time consequences of the dependencies it detects. Certain programs may contain hundreds of unreachable break statements, and lint will give a warning for each of them. The shear number of lint messages issued can be distracting. lint, however, provides command line options and directives to help suppress warnings you consider to be spurious.
For the example we've cited here,
/ NOTREACHED /
to suppress the diagnostic
for that statement.
Nearly five hundred diagnostic messages are issued by lint. However, this chapter only describes those lint-specific warnings that are not issued by the compiler. Additionally, this chapter lists diagnostics issued both by lint and the compiler that are capable of being suppressed only by lint options. For the text and examples of all messages issued exclusively by lint or subject exclusively to its options, refer to ``Understanding lint-specific messages''. For the messages also issued by the compiler, consult ``C compiler diagnostics''.
Most of lint's messages are simple, one-line statements printed for each occurrence of the problem they diagnose. Errors detected in included files are reported multiple times by the compiler but only once by lint, no matter how many times the file is included in other source files. Compound messages are issued for inconsistencies across files and, in a few cases, for problems within them as well. A single message describes every occurrence of the problem in the file or files being checked. When use of a lint filter requires that a message be printed for each occurrence, compound diagnostics can be converted to the simple type by invoking lint with the -s option.