Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!agate!shelby!decwrl!shlump.nac.dec.com!shodha.dec.com!devine From: devine@shodha.dec.com (Bob Devine) Newsgroups: comp.lang.c Subject: Re: More NULL questions Message-ID: <443@shodha.dec.com> Date: 6 Oct 89 19:05:08 GMT References: <5950001@hpldola.HP.COM> Organization: Digital Equipment Corp. - Colorado Springs, CO. Lines: 27 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: > if (ptr != (struct thing *)NULL) ... No danger. The comparison of `ptr' with NULL causes the NULL to be converted to the correct type. Look at the binary ops conversions. I consider it good coding style to put the cast there; it lets the future reader understand the code with less puzzlement. > 2) Is there danger using > int a, b; > my_func(a, NULL, b); > as apposed to > my_func(a, (struct thing *)NULL, b); You are in trouble if you do not use function prototypes if your system's pointer representation is not the same size as an int. Moreover if the pointer has some strange bit pattern representation then the NULL may not be passed correctly. Other places where a conversion takes place without the explicit cast are: in returns, assignments, and all ops. Bob Devine