HP C Programmer's Guide (92434-90009)

174 Chapter7
Using C Programming Tools
Using lint
int begin on a four-byte boundary. The following structure will be aligned differently on
the two architectures:
struct s
{ char c;
long l; /* The offset equals 2 on MC680x0 computers */
}; /* and 4 on PA-RISC computers. */
In many cases the different alignment of structures does not affect the behavior of a
program. However, problems can happen when raw structures are written to a file on one
architecture and read back in on another. The lint command checks for cases where a
structure member is aligned on a boundary that is not a multiple of its size (for example,
int on int boundary, short on short boundary, and double on double boundary). The
warning that it outputs is:
warning: alignment of struct 'name' may not be portable
The lint command also checks for cases where the internal padding added at the end of a
structure may differ between architectures. The amount of trailing padding can change the
size of a structure. The warning that lint outputs is:
warning: trailing padding of struct/union 's' may not be portable
Strange Constructions
A
strange construction
is code that lint considers to be bad style or a possible bug.
The lint command looks for code that has no effect. For example,
*p;
where the * has no effect. The statement is equivalent to "p;". In cases like this, the
message
warning: null effect
is sent.
The treatment of unsigned numbers as signed numbers in comparison causes lint to
report the following:
warning: degenerate unsigned comparison
The following code would produce such a message:
unsigned x;
.
.
.
if (x >=0) ...
The lint command also objects if constants are treated as variables. If the boolean
expression in a conditional has a set value due to constants, such as
if(1 !=0) ...
lint's response is:
warning: constant in conditional context
To avoid operator precedence confusion, lint encourages using parentheses in expressions