HP C Programmer's Guide (92434-90009)

Chapter 7 173
Using C Programming Tools
Using lint
character comparisons
pointer alignments (this is default on PA-RISC computers)
length of external variables
type casting
Character representation varies on different machines. Characters may be implemented
as signed values. As a result, certain comparisons with characters give different results on
different machines. The expression
c<0
where c is defined as type char, is always false if characters are unsigned values. If,
however, characters are signed values, the expression could be either true or false. Where
character comparisons could result in different values depending on the machine used,
lint outputs the message:
warning: nonportable character comparison
Legal pointer assignments are determined by the alignment restrictions of the particular
machine used. For example, one machine may allow double-precision values to begin on
any modulo-4 boundary, but another may restrict them to modulo-8 boundaries. If
alignment requirements are different, code containing an assignment of a double pointer
to an integer pointer could cause problems. The lint command attempts to detect where
the effect of pointer assignments is machine dependent. The warning that it outputs is:
warning: possible pointer alignment problem
The amount of information about external symbols that is loaded depends on: the machine
being used, the number of significant characters, and whether or not uppercase/lowercase
distinction is kept. The lint -p command truncates all external symbols to six characters
and allows only one case distinction. (It changes uppercase characters to lowercase.) This
provides a worst-case analysis so that the uniqueness of an external symbol is not
machine-dependent.
The effectiveness of type casting in C programs can depend on the machine that is used.
For this reason, lint ignores type casting code. All assignments that use it are subject to
lint's type checking.
Alignment Portability
The -s option of the lint command checks for the following portability considerations:
pointer alignments (same as -p option)
a structure's member alignments
trailing padding of structures and unions
The checks made for pointer alignments are exactly the same as for the -p option. The
warning for these cases is:
warning: possible pointer alignment problem
The alignment of structure members is different between architectures. For example,
MC680x0 computers pad structures internally so that all fields of type int begin on an
even boundary. In contrast, PA-RISC computers pad structures so that all fields of type