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.

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

The type checking rules also require that, in structure references, the left operand of a<br />

pointer arrow symbol ( ->) be a pointer to a structure, the left operand of a period (.) be<br />

a structure, and the right operand of these operators be a member of the structure<br />

implied by the left operand. Similar checking is done for references to unions.<br />

Strict rules apply to function argu ment and return value ma<strong>tc</strong>hing. The types float and<br />

double may be freely ma<strong>tc</strong>hed, as may the types char, short, int, and unsigned. Pointers<br />

can also be ma<strong>tc</strong>hed with the associated arrays. Aside from these relaxations in type<br />

checking, all actual arguments must agree in type with their declared counterparts.<br />

For enumerations, checks are made that enumeration variables or members are not<br />

mixed with other types or other enu merations, and that the only operations applied are<br />

assignment (=), initialization, equals (==), and not-equals (!=). Enumerations may also be<br />

function arguments and return values.<br />

Checking Type Casts<br />

The type cast feature in C was introduced largely as an aid to producing more portable<br />

programs. Consider the assignment<br />

p = 1;<br />

where p is a character pointer. lint reports this as suspect. But consider the assignment<br />

p = (char *)1 ;<br />

in which a cast has been used to convert the integer to a character pointer. The<br />

programmer obviously had a strong motivation for doing this, and has clearly signaled<br />

his intentions. On the other hand, if this code is moved to another machine, it should be<br />

looked at carefully. The -c option controls the printing of comments about casts. When<br />

-c is in effect, casts are not checked and all legal casts are passed without comment, no<br />

matter how strange the type mixing seems to be.<br />

Checking for Non portable Character Use<br />

lint flags certain comparisons and assignments as illegal or nonportable. For example,<br />

the fragment<br />

char c;<br />

if( (c = ge<strong>tc</strong>har( )) < 0) ...<br />

works on some machines but fails on machines where characters always take on positive<br />

values. The solution is to declare c an integer, since ge<strong>tc</strong>har is actually returning<br />

integer values. In any case, lint issues the message<br />

nonportable character comparison<br />

3-7

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

Saved successfully!

Ooh no, something went wrong!