Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!voder!pyramid!octopus!comp.lang.c Newsgroups: comp.lang.c Subject: Re: if (!pointer) as portable as if (pointer == NULL) Message-ID: <1990Apr12.183036.16541@Octopus.COM> Date: 12 Apr 90 18:30:36 GMT Sender: Michael Morris Organization: Octopus Enterprises, Cupertino CA Lines: 23 >In article <1461@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: >>In article <656@hades.OZ> greyham@hades.OZ (Greyham Stoney) writes: >> >> if (buffer) free(buffer) >> >>This is also portable, and almost readable. Again, to be really readable, >>you should still compare to NULL, but I grant that it would make your >>source code longer this time. > >How about just a: > free(buffer) > >The manual pages I know allow a NULL pointer and doing nothing in this case. >Is this generally true ? Using the free function with a NULL pointer may be o.k with some compilers, but don't try that with other functions since you may get unpredictable results. Using MSC 5.1 I had a few calls which didn't check to see if the pointer was NULL prior to calling fclose(fileptr), and fclose ended up writing garbage into the interrupt vector table. -- Michael Morris, Strategic Mapping Inc. {hpda,pyramid}!octopus!slp!mikem