HP C Programmer's Guide (92434-90009)

170 Chapter7
Using C Programming Tools
Using lint
detected. They have the following form:
(
line #
) warning:
message text
Information about external functions and variables is collected and analyzed after lint
has processed the source files. At that time, if a problem has been detected, it outputs a
warning message with the form
message text
followed by a list of external names causing the message and the file where the problem
occurred.
Code causing lint to issue a warning message should be analyzed to determine the source
of the problem. Sometimes the programmer has a valid reason for writing the problem
code. Usually, though, this is not the case. The lint command can be very helpful in
uncovering subtle programming errors.
The lint command checks the source code for certain conditions, about which it issues
warning messages. These can be grouped into the following categories:
variable or function is declared but not used
variable is used before it is set
portion of code is unreachable
function values are used incorrectly
type matching does not adhere strictly to C rules
code has portability problems
code construction is strange
The code that you write may have constructions in it that lint objects to but that are
necessary to its application. Warning messages about problem areas that you know about
and do not plan to correct can be suppressed. There are two methods for suppressing
warning messages from lint. The use of lint options is one. The lint command can be
called with any combination of its defined option set. Each option causes lint to ignore a
different problem area. The other method is to insert lint directives into the source code.
For information about lint directives, see the section "Directives" in this chapter.
Unused Variables and Functions
The lint command objects if source code declares a variable that is never used or defines a
function that is never called. Unused variables and functions are considered bad style
because their declarations clutter the code.
Unused static identifiers cause the following message:
(1)static identifier
'name'
defined but never used
Unused automatic variables cause the following message:
(1) warning:
'name'
unused in function
'name'
A function or external variable that is unused causes the message
name defined but never used