Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!ames!uhccux!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c Subject: Re: More NULL questions Message-ID: <2320@munnari.oz.au> Date: 7 Oct 89 09:20:24 GMT References: <5950001@hpldola.HP.COM> Sender: news@cs.mu.oz.au Lines: 29 In article <5950001@hpldola.HP.COM>, jg@hpldola.HP.COM (Joe Gilray) writes: > 1) what is the danger with using > struct thing *ptr; ... if (ptr != NULL) ... > as Opposed to > struct thing *ptr; ... if (ptr != (struct thing *)NULL) ... None. You can even use ... if (ptr) ... > 2) Is there danger using > int a, b; ... my_func(a, NULL, b); > as Opposed to > int a, b; ... my_func(a, (struct thing *)NULL, b); > when > a) you are using function prototypes? No. If there is a prototype in scope, passing an argument is like assignment, NULL will be converted to the appropriate pointer type. > b) you are NOT using function prototypes (like me)? Yes. You will get an int, which may not be the same size as a pointer, and if it is, may not be the same bit pattern as (struct thing *)NULL. It isn't just NULL. With some C compilers, and on some machines, the cast in struct thing *ptr; ... if (fwrite((char *)ptr, sizeof *ptr, 1, stream) != 1) ... is absolutely necessary. (The cast is (void *) in ANSI C, and is not needed if you have the prototype of fwrite() in scope.)