Just a minor new twist on free()
Walter Bright
bright at nazgul.UUCP
Thu Oct 25 08:21:49 AEST 1990
In article <1990Oct02.132313.6659 at virtech.uucp> cpcahil at virtech.UUCP (Conor P. Cahill) writes:
<In article <PDS.90Oct1095707 at lemming.webo.dg.com> pds at lemming.webo.dg.com (Paul D. Smith) writes:
<<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).
<While this is a true statement, I would never recommend that one take advantage
<of this feature. If you know the variable is NULL don't pass it to free.
<The performance cost of the following statement:
< if( ptr != NULL )
< free(ptr);
<as opposed to:
< free(ptr);
<will be unmeasurable in most, if not all, circumstances. In addition, by
<adding the if() you get code that is portable across all implementations.
I'd prefer to use, on non-conforming implementations of free():
#if NONCONFORMINGFREE
#define free(p) ((p) && free(p))
#endif
More information about the Comp.lang.c
mailing list