Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!dg!fs06!pds From: pds@lemming.webo.dg.com (Paul D. Smith) Newsgroups: comp.lang.c Subject: Re: Just a minor new twist on free() Message-ID: Date: 1 Oct 90 13:57:07 GMT References: <7365@darkstar.ucsc.edu> Sender: root@dg.dg.com Organization: NSDD/ONAD, Data General Corp., Westboro, MA Lines: 27 In-reply-to: funkstr@ucscb.ucsc.edu's message of 1 Oct 90 00:25:13 GMT In article <7365@darkstar.ucsc.edu> funkstr@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@lemming.webo.dg.com | | Data General Corp. | | | Network Services Development | "Pretty Damn S..." | | Open Network Applications Department | | ------------------------------------------------------------------