Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Just a minor new twist on free() Message-ID: <1990Oct02.132313.6659@virtech.uucp> Date: 2 Oct 90 13:23:13 GMT References: <7365@darkstar.ucsc.edu> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 28 In article pds@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. Anyway, this is really a moot point because you should never be calling free() unless you KNOW WHAT IS IN THE PTR that you will be passing to it. If you don't, then something is wrong with your code. -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170