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 Expression Evaluation Order In complicated expressions, the best order in which to evaluate subexpressions may be highly machine-dependent. For example, on machines in which the stack runs backward, function arguments will probably be best evaluated from right to left; on machines with a stack running forward, left to right is probably best. Function calls embedded as arguments of other functions may or may not be treated in the same way as ordinary arguments. Sim ilar issues arise with other operators that have side effects, such as the assignment operators and the increment and decrement operators. So that the efficiency of C on a particular machine is not unduly compromised, the C language leaves the order of evaluation of complicated expressions up to the compiler, and various C compilers have considerable differences in the order in which they will evaluate complicated expressions. In particular, if any variable is changed by a side effect, and also used elsewhere in the same expression, the result is explicitly undefined. lint checks for the important special case where a simple scalar variable is affected. For example, the statement a[i] = b[i + +] ; will draw the comment warning: i evaluation order undefined Embedding Directives There are occasions when the program mer is smarter than lint. There may be valid reasons for illegal type casts, functions with a variable number of arguments, and other constructions that lint finds objectionable. Moreover, as specified in the above sections, the flow of control information produced by lint often has blind spots, causing occasional spurious messages about perfectly reasonable programs. Some way of communicating with lint, typically to turn off its output, is desirable. Therefore, a number of words are recognized by lint when they are embedded in com ments in a C source file. These words are called directives. lint directives are invisible to the compiler. The first directive discussed concerns flow of control information. If a particular place in the program cannot be reached, this can be asserted at the appropriate spot in the program with the directive I* NOTREACHED *I Similarly, if you desire to turn off strict type checking for the next expression, use the directive I* NOSTRICT *I 3-11

lint: C Program Checker XENIX Programming The situation reverts to the previous default after the next expression. The -v option can be turned on for one function with the directive I* ARGSUSED *I Comments about a variable number of arguments in calls to a function can be turned off by preceding the function definition with the directive I* VARARGS *I In some cases, you may want to check the first several arguments and leave the later arguments unchecked. Do this by following the VARARGS keyword immediately with a digit giving the number of arguments that should be checked. Thus I* VARARGS2 *I causes only the first two argu ments to be checked. Finally, the directive I* LINTLIBRARY *I at the head of a file identifies this file as a library declaration file, discussed in the next section. Checking for Library Compatibility lint accepts certain library directives, such as -ly and tests the source files for compatibility with these libraries. This testing is done by accessing library description files whose names are constructed from the library directives. These files all begin with the directive I* LINTLIBRARY *I which is followed by a series of dummy function definitions. The critical parts of these definitions are the declaration of the function return type, whether the dummy function returns a value, and the number and types of argu ments to the function. The "VARARGS" and "ARGSUSED" directives can be used to specify features of the library functions. lint library files are processed almost exactly like ordinary source files. The only difference is that functions defined in a library file but not used in a source file, draw no com ments. lint does not simulate a full library search algorithm. lint does check to see if the source files contain redefinitions of library routines. By default, lint checks the programs it is given against a standard library file, which contains descriptions of the standard functions that are normally loaded when a C program is run. When the -p option is in effect, the portable libarary file is checked containing descriptions of the standard 1/0 library routines which are expected to be portable across various machines. The -n option can be used to suppress all library checking. 3-1 2

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

Checking Expression Evaluation Order<br />

In complicated expressions, the best order in which to evaluate subexpressions may be<br />

highly machine-dependent. For example, on machines in which the stack runs backward,<br />

function arguments will probably be best evaluated from right to left; on machines with<br />

a stack running forward, left to right is probably best. Function calls embedded as<br />

arguments of other functions may or may not be treated in the same way as ordinary<br />

arguments. Sim ilar issues arise with other operators that have side effects, such as the<br />

assignment operators and the increment and decrement operators.<br />

So that the efficiency of C on a particular machine is not unduly compromised, the C<br />

language leaves the order of evaluation of complicated expressions up to the compiler,<br />

and various C compilers have considerable differences in the order in which they will<br />

evaluate complicated expressions. In particular, if any variable is changed by a side<br />

effect, and also used elsewhere in the same expression, the result is explicitly<br />

undefined.<br />

lint checks for the important special case where a simple scalar variable is affected.<br />

For example, the statement<br />

a[i] = b[i + +] ;<br />

will draw the comment<br />

warning: i evaluation order undefined<br />

Embedding Directives<br />

There are occasions when the program mer is smarter than lint. There may be valid<br />

reasons for illegal type casts, functions with a variable number of arguments, and other<br />

constructions that lint finds objectionable. Moreover, as specified in the above sections,<br />

the flow of control information produced by lint often has blind spots, causing<br />

occasional spurious messages about perfectly reasonable programs. Some way of<br />

communicating with lint, typically to turn off its output, is desirable. Therefore, a<br />

number of words are recognized by lint when they are embedded in com ments in a C<br />

source file. These words are called directives. lint directives are invisible to the<br />

compiler.<br />

The first directive discussed concerns flow of control information. If a particular place<br />

in the program cannot be reached, this can be asserted at the appropriate spot in the<br />

program with the directive<br />

I* NOTREACHED *I<br />

Similarly, if you desire to turn off strict type checking for the next expression, use the<br />

directive<br />

I* NOSTRICT *I<br />

3-11

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

Saved successfully!

Ooh no, something went wrong!