Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: free (NULL); Keywords: free Message-ID: <1990May8.123635.20841@virtech.uucp> Date: 8 May 90 12:36:35 GMT References: <1194@wet.UUCP> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 23 In article <1194@wet.UUCP> noah@wet.UUCP (Noah Spurrier) writes: >This function is run many times so iI do not want to protect it with an if >because the if would only be useful for the first time it is run, after that >it just eats up run time. > > if (test != NULL) > free (test); The test of a variable against zero is one of the most efficient operations performed in a computer. Even if you called the function millions of times during program execution, you probably couldn't tell whether or not the if is present because of it's small use of CPU power. >Will angry things happen if I try to free(NULL) ? Undefined. Maybe, maybe not. Why take the chance? You won't be saving any measurable CPU time. -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170