Just a minor new twist on free()

Kevin D. Quitt kdq at demott.COM
Wed Oct 3 01:39:43 AEST 1990


In article <PDS.90Oct1095707 at lemming.webo.dg.com> pds at lemming.webo.dg.com (Paul D. Smith) writes:
>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; }
>

    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 at 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.



More information about the Comp.lang.c mailing list