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 />

If the variable is used in the same statement in which it is assigned for the first time,<br />

lint determines the order of evaluation of the statement and displays an appropriate<br />

message. For example, in the program fragment<br />

int i, total;<br />

scanf("%d", &i);<br />

total = total + i;<br />

lint warns that the variable "total" is used before it is set since it appears on the right<br />

side of the same statement that assigns its first value.<br />

Static and external variables are always initialized to zero before program execution<br />

begins, so lint does not report such variables if they are used before being set to a value.<br />

Checking for Unreachable Statements<br />

The lint ·program checks for unreachable statements, that is, for unlabeled statements<br />

that immediately follow a goto, break, continue, or return statement. During execution<br />

of a program, the unreachable statements never receive execution control and are<br />

therefore considered wasteful. For example, in the program fragment<br />

int x,y;<br />

return (x + y);<br />

exit (1);<br />

the function call exit after the return statement is unreachable.<br />

Unreachable statements are common when developing programs containing large swi<strong>tc</strong>h<br />

statements or loops containing break and continue statements. Such statements are<br />

wasteful and should be removed.<br />

During normal operation, lint reports all unreachable break statements. Unreachable<br />

break statements are relatively common (some programs created by the yacc and lex<br />

programs contain hundreds), so it may be desirable to suppress these reports. You can<br />

direct lint to suppress the reports by using the -b option.<br />

Note that lint assumes that all functions eventually return control, so it does not report<br />

as unreachable any statement that follows a function that takes control and never<br />

returns it. For example:<br />

exit (1 );<br />

return;<br />

The call to exit causes the return statement to become an unreachable statement, but<br />

lint does not report it as such.<br />

3-4

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

Saved successfully!

Ooh no, something went wrong!