Path: utzoo!attcan!uunet!mailrus!ncar!noao!stsci!ansok From: ansok@stsci.EDU (Gary Ansok) Newsgroups: comp.lang.c Subject: Re: What C compilers have non-zero null pointers? Message-ID: <1618@stsci.edu> Date: 22 Jul 90 15:18:53 GMT References: <9007161750.AA00664@edison.CHO.GE.COM> <12288@netcom.UUCP> Reply-To: ansok@stsci.edu.UUCP (Gary Ansok) Organization: Space Telescope Science Institute, Baltimore, MD 21218 Lines: 39 In article <12288@netcom.UUCP> ergo@netcom.UUCP (Isaac Rabinovitch) writes: >True. But what the "NULL should always be 0" diehards want is not to >write (for example) > > for (ptr = fist; ptr != 0; ptr = ptr->next) > >in which 0 should probably be #DEFINED anyway, but rather > > for (ptr = first; ptr ; ptr = ptr->next) > >which produces tighter code and (most important of all) looks >spiffier. It has the elegance of expression old C hands crave. Once more with feeling: if (ptr) /* or for(;ptr;) */ is exactly equivalent to if (ptr != 0) which is exactly equivalent to if (ptr != (typeof ptr) 0) which is exactly equivalent to if (ptr != NULL-pointer-for-typeof-ptr) Any C compiler that has a not-all-bits-zero NULL internal representation and does not compare a pointer to that in "if (ptr)" or "for (...; ptr; ...)" is seriously BROKEN. Whether you like "if (ptr)" on readability grounds is a different question (I like it, but I seem to be in the minority) -- but that's purely a style question and the compiler had better produce the correct code. Gary Ansok ansok@stsci.edu