Just a minor new twist on free()
Gary Duzan
gdtltr at freezer.it.udel.edu
Fri Oct 12 11:42:45 AEST 1990
In article <4d5780ad.20b6d at apollo.HP.COM> blodgett at apollo.HP.COM (Bruce Blodgett) writes:
=>
=>If you are trying to compile code which may call free() with a NULL
=>argument, and use an implementation of free() that does not handle NULL
=>gracefully, try adding one of the following to <stdlib.h>:
=>
=>#define free(x) ( (x) ? free(x) : ( (void)0 ) )
=> or
=>#define free(x) { void * ptr = (x); if ( ptr != NULL ) free(ptr); }
=>
=>The former has the side-effect of evaluating the argument to free()
=>twice. The latter is a statement rather than an expression of type
=>void, and therefore wouldn't work if someone tried to embed a call to
=>free() in an expression (there are not many uses for subexpressions of
=>type void).
Both will also have the property of recursively expanding free() forever.
Better to call it something else. Your cpp will thank you for it.
Gary Duzan
Time Lord
Third Regeneration
--
gdtltr at freezer.it.udel.edu
_o_ -------------------------- _o_
[|o o|] An isolated computer is a terribly lonely thing. [|o o|]
|_O_| "Don't listen to me; I never do." -- Doctor Who |_O_|
More information about the Comp.lang.c
mailing list