if (!pointer) as portable as if (pointer == NULL)


Fri Apr 13 04:30:36 AEST 1990


>In article <1461 at tkou02.enet.dec.com> diamond at tkou02.enet.dec.com (diamond at tkovoa) writes:
>>In article <656 at hades.OZ> greyham at 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



More information about the Comp.lang.c mailing list