Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: use of NULL Keywords: NULL zero 0 C Microsoft Message-ID: <16106@mimsy.UUCP> Date: 24 Feb 89 10:33:27 GMT References: <1167@unisec.usi.com. <5312@turnkey.TCC.COM. <9582@smoke.BRL.MIL. <20928@shemp.CS.UCLA.EDU> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 21 In article <20928@shemp.CS.UCLA.EDU> heather@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@mimsy.umd.edu Path: uunet!mimsy!chris