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.

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

Note that the lint program does not report a variable or function unused if it is<br />

explicitly declared with the extern storage class. Such a variable or function is assumed<br />

to be used in another source file.<br />

You can direct lint to ignore all the external declarations in a source file by using the -x<br />

{for "external") option. The option causes the program checker to skip any line that<br />

begins with the extern storage class.<br />

The option is typically used to save time when checking a program, especially if all<br />

external declarations are known to be valid.<br />

Some programming styles require functions that perform closely related tasks to have<br />

the same number and type of arguments regardless of whether or not these arguments<br />

are used. Under normal operation, lint reports any argument not used as an unused<br />

variable, but you can direct lint to ignore unused arguments by using the -v option. The<br />

-v option causes lint to ignore all unused function arguments except for those declared<br />

with register storage class. The program considers unused arguments of this class to be<br />

a preventable waste of the register resources of the computer.<br />

You can direct lint to ignore all unused variables and functions by using the -u {for<br />

"unused") option. This option prevents lint from reporting variables and functions it<br />

considers unused.<br />

This option is typically used when checking a source file that contains just a portion of a<br />

large program. Such source files usually contain declarations of variables and functions<br />

to be used in other source files that are not explicitly used within the file. Since lint can<br />

check only the given file, it normally assumes that such variables or functions are<br />

unused and reports them as errors.<br />

Checking Local Variables<br />

The lint program checks all local variables to see that they are set to a value before<br />

being used. Since local variables have either automatic or register storage class, their<br />

values at the start of the program or function cannot be known. Using such a variable<br />

before assigning a value to it is an error.<br />

The program checks the local variables by searching for the first assignment in which<br />

the variable receives a value and the first statement or expression in which the variable<br />

is used. If the first assignment appears later than the first use, lint considers the<br />

variable inappropriately used. For example, in the program fragment<br />

int c;<br />

if ( c ! = EOT )<br />

c = ge<strong>tc</strong>har( );<br />

lint warns that the the variable c is used before it is assigned.<br />

3-3

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

Saved successfully!

Ooh no, something went wrong!