Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!srhqla!demott!kdq From: kdq@demott.COM (Kevin D. Quitt) Newsgroups: comp.lang.c Subject: Re: Just a minor new twist on free() Message-ID: <629@demott.COM> Date: 2 Oct 90 15:39:43 GMT References: Reply-To: kdq@demott.COM (Kevin D. Quitt) Organization: DeMott Electronics Co., Van Nuys CA Lines: 29 In article pds@lemming.webo.dg.com (Paul D. Smith) writes: >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; } > Actually, execution time will be saved by the original definition, since it avoids the call/return overhead in invoking free when the pointer is null. This was discussed a month or so ago, and timings were published. -- _ Kevin D. Quitt demott!kdq kdq@demott.com DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266 VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last 96.37% of all statistics are made up.