Just a minor new twist on free()
Paul D. Smith
pds at lemming.webo.dg.com
Mon Oct 1 23:57:07 AEST 1990
In article <7365 at darkstar.ucsc.edu> funkstr at ucscb.ucsc.edu (Larry Hastings) writes:
[] #define smart_free(x) { if (x != NULL) { free(x); x = NULL; } }
It should be pointed out that in ANSI C free(NULL) is defined, and is
legal (any conforming implementation of free() must ignore being
passed a NULL pointer).
So, you could save yourself some execution time (if you have an ANSI
compiler) by writing:
#define smart_free(x) { free(x); x = NULL; }
(you may also want to peruse the seperate thread in this newsgroup on
multi-statement macros and `while(0)' loops, etc.)
--
paul
-----
------------------------------------------------------------------
| Paul D. Smith | pds at lemming.webo.dg.com |
| Data General Corp. | |
| Network Services Development | "Pretty Damn S..." |
| Open Network Applications Department | |
------------------------------------------------------------------
More information about the Comp.lang.c
mailing list