Path: utzoo!attcan!uunet!seismo!dimacs.rutgers.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!phigate!ehviea!leo From: leo@ehviea.ine.philips.nl (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: What C compilers have non-zero null pointers? Message-ID: <832@ehviea.ine.philips.nl> Date: 18 Jul 90 11:08:24 GMT References: <9007161750.AA00664@edison.CHO.GE.COM> <1990Jul17.123627.1932@druid.uucp> Reply-To: leo@ehviea.UUCP (Leo de Wit) Organization: Philips I&E Eindhoven Lines: 31 In article <1990Jul17.123627.1932@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes: [] |However I always use NULL for two reasons. Broken compilers on brain dead |CPUs and if NULL is defined as "(void *)0" then it tests for accidentally |testing a NULL pointer against a non pointer variable. For example: | int a = 0; | if (a == NULL) | do(something); |If tested against 0 the compiler won't complain but it will complain if it |is tested against (void *)0. At least GNU C complains. In other words, use |NULL not because 0 may not be the NULL pointer but because NULL can't be |anything else. For much the same reason I always use explicit casts for null pointers; this also catches unadvertent assignments or comparisions to a pointer of a different type, and has the additional advantage that null pointers as parameters have the same "appearance"; you don't have to develop different habits of treating pointers. As an example: if (fgets(inbuf,sizeof(inbuf),fp) != (char *)0) .... but also: execl("/bin/ls","ls",(char *)0); Another advantage is that you see immediately from the program text what kind of pointer is expected at some stage; in production code, and especially in the maintenance phase, this may prevent a lot of type lookups. Leo.