use of NULL

Chris Torek chris at mimsy.UUCP
Fri Feb 24 20:33:27 AEST 1989


In article <20928 at shemp.CS.UCLA.EDU> heather at SEAS.UCLA.EDU writes:
>Excuse me for a probably naive question that I've had since following the
>discussion of passing NULL to functions: Why doesn't the C standard
>treat NULL or 0 (a static/constant NULL or 0, i.e. indicated at compile time)
>passed to a function that has a pointer value in the function prototype 
>as a special case and do the cast implicitly?

This is a perfectly reasonable question, with a perfectly reasonable
answer.  It is not a special case and it works just fine.  The key
is the phrase `function prototype':  Not all compilers handle prototypes,
and not all programs include prototypes.

If the compiler does not *know* that the first argument to strtok() has
type `char *', it cannot convert a 0 argument to a nil-pointer-to-char.
It passes an int-0 (or, with Microsoft's `0L' definition, a long-0)
simply because it does not know any better.  Give it the information
(in the form of a prototype declaration, or a cast at invocation, or
both) and it does the conversion.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list