HP C Programmer's Guide (92434-90009)

Chapter 7 169
Using C Programming Tools
Using lint
The lint command accepts certain arguments, such as:
-lm
The lint library files are processed almost exactly like ordinary source files. The only
difference is that functions that are defined on a library file but are not used on a source
file do not result in messages. The lint command does not simulate a full library search
algorithm and will print messages if the source files contain a redefinition of a library
routine.
By default, lint checks the programs it is given against a standard library file which
contains descriptions of the programs which are normally loaded when a C language
program is run. When the -p option is used, another file is checked containing descriptions
of the standard library routines which are expected to be portable across various
machines. The -n option can be used to suppress all library checking.
lint also recognizes the -LINTLIBRARY the HP C -Wp option. The lint -LINTLIBRARY
option is equivalent to using lint comment /*LINTLIBRARY*/ in source files. lint also
recognizes the -Wp option and passes named arguments to the preprocessor.
Directives
The alternative to using options to suppress lint's comments about problem areas is to
use directives. Directives appear in the source code in the form of code comments. The
lint command recognizes five directives.
/*NOTREACHED*/ Stops an unreachable code comment about the next line of code.
/*NOSTRICT*/ Stops lint from strictly type checking the next expression.
/*ARGSUSED*/ Stops a comment about any unused parameters for the following function.
/*VARARGS
n
*/ Stops lint from reporting variable numbers of parameters in calls to a
function. The function's definition follows this comment. The first
n
parameters must be present in each call to the function; lint comments if
they aren't. If /*VARARGS*/ appears without the
n
, none of the parameters
must be present. This comment must precede the actual code for a
function. It
should not
precede extern declarations.
/*LINTLIBRARY*/ Tells lint that the source file is used to create a lint library file and
to suppress comments about the unused functions. lint objects if other
files redefine routines that are found there. This directive must be placed
at the beginning of a source file.
Problem Detection
Remember that a compiler reports errors only when it encounters program source code
that cannot be converted into object code. The main purpose of lint is to find problem
areas in C source code that it considers to be inefficient, nonportable, bad style, or a
possible bug, but which the C compiler accepts as error-free because it can be converted
into object code.
Comments about problems that are local to a function are produced as each problem is