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

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

09.06.2013 Views

XENIX Programming lint: C Program Checker Checking for Infin ite Loops The lint program checks for infinite loops and for loops that are never executed. For example, the statements and while (1) {} for (;;) {} are both considered infinite loops. While the statements and while (0) {} for (;0;) {} are never executed. Although some valid programs have such loops, they are generally considered errors. Checking Function Return Values The lint program checks that a function returns a meaningful value if necessary. Some functions return values that are never used; some programs incorrectly use function values that have never been returned. lint addresses these problems in a number of ways. Within a function definition, the appearance of both and return ( expr) ; return; statements is cause for alarm. In this case, lint produces the following error message: function name contains return(e) and return 3-5

lint: C Program Checker XENIX Programming It is difficult to detect when a function return is implied by the flow of control reaching the end of the given function. This is demonstrated with a simple example: f (a) { } if (a) g(); return (3); Note that if the variable a tests false, f will call the function g and then return with no defined return value. This will trigger a report from lint. If g, like exit, never returns, the message will still be produced when in fact nothing is wrong. In practice, potentially serious bugs can be discovered with this feature. It also accounts for a substantial fraction of the noise messages produced by lint. Checking for Unused Return Values The lint program checks for cases where a function returns a value, but the value is rarely if ever used. lint considers functions that return unused values to be inefficient and functions that return rarely used values to be a result of bad programming style. lint also checks for cases where a function does not return a value but the value is used anyway. This is considered a serious error. Checking Types lint enforces the type checking rules of C more strictly than the C compiler. The additional checking occurs in four major areas: • Across certain binary operators and implied assignments • At the structure selection operators • Between the definit ion and uses of functions • In the use of enumerations A number of operators, including the assignment, conditional, and relational operators, have an implied balancing between types of operands. The argument of a return statement and expressions used in initialization also suffer similar conversions. In these operations, char, short, int, long, unsigned, float, and double types can be freely intermixed. The types of pointers must agree exactly, except that arrays of x's can be intermixed with pointers to x's. 3-6

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

Checking for Infin ite Loops<br />

The lint program checks for infinite loops and for loops that are never executed. For<br />

example, the statements<br />

and<br />

while (1) {}<br />

for (;;) {}<br />

are both considered infinite loops. While the statements<br />

and<br />

while (0) {}<br />

for (;0;) {}<br />

are never executed.<br />

Although some valid programs have such loops, they are generally considered errors.<br />

Checking Function Return Values<br />

The lint program checks that a function returns a meaningful value if necessary. Some<br />

functions return values that are never used; some programs incorrectly use function<br />

values that have never been returned. lint addresses these problems in a number of<br />

ways.<br />

Within a function definition, the appearance of both<br />

and<br />

return ( expr) ;<br />

return;<br />

statements is cause for alarm. In this case, lint produces the following error message:<br />

function name contains return(e) and return<br />

3-5

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

Saved successfully!

Ooh no, something went wrong!