09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

lint: C Program Checker <strong>XENIX</strong> Programming<br />

A similar issue arises with bitfields. When assignments of constant values are made to<br />

bitfields, the field may be too small to hold the value. This is especially true here on<br />

some machines bitfields are considered as signed quantities. While it may seem<br />

counter-intuitive to consider that a 2-bit field declared of type int cannot hold the value<br />

3, the problem disappears if the bitfield is declared to have type unsigned.<br />

Checking for Assignment of longs to ints<br />

Bugs may arise from the assignment of a long to an int, because of a loss in accuracy in<br />

the process. This may happen in programs that have been incompletely converted by<br />

changing type definitions with typedef. When a typedef variable is changed from int to<br />

long, the program can stop working because some intermediate results may be assigned<br />

to integer values, losing accuracy. Since there are a number of legitimate reasons for<br />

assigning longs to integers, you may wish to suppress detection of these assignments by<br />

using the -a option.<br />

Checking for Strange Constructions<br />

Several perfectly legal but somewhat strange constructions are flagged by lint. The<br />

generated messages encourage better code quality and clearer style, and may even point<br />

out bugs. For example, in the statement<br />

*p + + ;<br />

the asterisk (*) does nothing and lint prints<br />

null effect<br />

The program fragment<br />

unsigned x;<br />

if (x < 0) ...<br />

is also strange since the test will never succeed. Similarly, the test<br />

unsigned x;<br />

if (x > 0) ...<br />

is equivalent to<br />

3-8<br />

unsigned x;<br />

if( X ! = 0) ...

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!