HP C Programmer's Guide (92434-90009)

Chapter 7 171
Using C Programming Tools
Using lint
followed by the function or variable name, the line number and file in which it was defined.
The lint command also looks at the special case where one of the parameters of a function
is not used. The warning message is:
warning:
(line number) 'arg_name'
in
func_name'
If functions or external variables are declared but never used or defined, lint responds
with
name declared but never used or defined
followed by a list of variable and functions names and the names of files where they were
declared.
Suppressing Unused Functions and Variables Reports
Sometimes it is necessary to have unused function parameters to support consistent
interfaces between functions. The -v option can be used with lint to suppress warnings
about unused parameters.
If lint is run on a file that is linked with other files at compile time, many external
variables and functions can be defined but not used, as well as used but not defined. If
there is no guarantee that the definition of an external object is always seen before the
object code is used, it is declared extern. The -u option can be used to stop complaints
about all external objects, whether or not they are declared extern. If you want to inhibit
complaints about only the extern declared functions and variables, use the -x option.
Set/Used Information
A problem exists in a program if a variable's value is used before it is assigned. Although
lint attempts to detect occurrences of this, it takes into account only the physical location
of the code. If code using a local variable is located before the variable is given a value, the
message is:
warning:
'name'
may be used before set
The lint command also objects if automatic variables are set in a function but not used.
The message given is:
warning:
'name'
set but not used in function
'func_name'
Note that lint
does not
have an option for suppressing the display of warnings for
variables that are used but not set or set but not used.
Unreachable Code
The lint command checks for three types of unreachable code. Any statement following a
goto, break, continue, or return statement must either be labeled or reside in an outer
block for lint to consider it reachable. If neither is the case, lint responds with:
warning:
(line number)
statement not reached
The same message is given if lint finds an infinite loop. It only checks for the infinite loop
cases of while(1) and for(;;). The third item that lint looks for is a loop that cannot be
entered from the top. If one is found, then the message sent is:
warning: loop not entered from top