Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!crdgw1!sungod!davidsen From: davidsen@sungod.crd.ge.com (ody) Newsgroups: comp.lang.c Subject: Re: effect of free() Message-ID: <1769@crdgw1.crd.ge.com> Date: 18 Aug 89 21:39:55 GMT References: <319@cubmol.BIO.COLUMBIA.EDU> <3756@buengc.BU.EDU><320@cubmol.BIO.COLUMBIA.EDU> <3777@buengc.BU.EDU> <1989Aug17.005548.745@twwells.com> Sender: news@crdgw1.crd.ge.com Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric Corp. R&D, Schenectady, NY Lines: 21 In article <1989Aug17.005548.745@twwells.com> bill@twwells.com (T. William Wells) writes: | | char *ptr; | | ptr = malloc(1); | ... | free(ptr); | ... | if (ptr == 0) ... | | The if might cause a trap when the value of ptr is accessed. As far as I can see you have to be able to test the value of a pointer to see if it's valid in any implementation, and as long as you don't dereference the pointer I don't see any portability problems. The test to see if ptr is zero (ie. NULL) would be better placed after the malloc, before trying the free... bill davidsen (davidsen@crdos1.crd.GE.COM) {uunet | philabs}!crdgw1!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me