Bellybutton lint

utzoo!decvax!harpo!eagle!mhtsa!alice!rabbit!ark utzoo!decvax!harpo!eagle!mhtsa!alice!rabbit!ark
Fri Apr 15 14:54:36 AEST 1983


The comment was that lint complains about 0 not matching pointers
in function calls but not elsewhere.  This is correct.  Consider:

	sometype *foo;
	foo = 0;

The assignment has the same effect as

	foo = (sometype *) 0;

0 is guaranteed to be convertible to a pointer, and it is guaranteed
that this resulting pointer will compare unequal to a pointer to any
actual data object.  The cast is unnecessary because the right hand
side of an assignment is what some people call a "strong context":
there is only one type that is legitimate in that context.

Now consider:

	f(0)

It is not possible, in general, to determine by inspection what type
f expects unless the definition of f is handy.  Suppose that f is:

	f (x) sometype *x; {...}

and that it is compiled elsewhere.  Now, an integer is being passed,
WITHOUT CONVERSION, to a function that expects a pointer.

You may say: So what?  Won't some kind of implicit conversion take place?
Well, maybe.  On some machines, it is convenient to have 16-bit integers
and 32-bit pointers.  Saying f(0) definitely won't work on these machines;
you must say

	f((sometype *) 0)

instead.  In C, an actual parameter is not a strong context.



More information about the Comp.lang.c mailing list