free (NULL);

Conor P. Cahill cpcahil at virtech.uucp
Tue May 8 22:36:35 AEST 1990


In article <1194 at wet.UUCP> noah at 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 



More information about the Comp.lang.c mailing list