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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

It is difficult to detect when a function return is implied by the flow of control reaching<br />

the end of the given function. This is demonstrated with a simple example:<br />

f (a)<br />

{<br />

}<br />

if (a)<br />

g();<br />

return (3);<br />

Note that if the variable a tests false, f will call the function g and then return with no<br />

defined return value. This will trigger a report from lint. If g, like exit, never returns,<br />

the message will still be produced when in fact nothing is wrong. In practice,<br />

potentially serious bugs can be discovered with this feature. It also accounts for a<br />

substantial fraction of the noise messages produced by lint.<br />

Checking for Unused Return Values<br />

The lint program checks for cases where a function returns a value, but the value is<br />

rarely if ever used. lint considers functions that return unused values to be inefficient<br />

and functions that return rarely used values to be a result of bad programming style.<br />

lint also checks for cases where a function does not return a value but the value is used<br />

anyway. This is considered a serious error.<br />

Checking Types<br />

lint enforces the type checking rules of C more strictly than the C compiler. The<br />

additional checking occurs in four major areas:<br />

• Across certain binary operators and implied assignments<br />

• At the structure selection operators<br />

• Between the definit ion and uses of functions<br />

• In the use of enumerations<br />

A number of operators, including the assignment, conditional, and relational operators,<br />

have an implied balancing between types of operands. The argument of a return<br />

statement and expressions used in initialization also suffer similar conversions. In these<br />

operations, char, short, int, long, unsigned, float, and double types can be freely<br />

intermixed. The types of pointers must agree exactly, except that arrays of x's can be<br />

intermixed with pointers to x's.<br />

3-6

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

Saved successfully!

Ooh no, something went wrong!