free (NULL);
Aaron Henley
henley at motcid.UUCP
Thu May 10 01:04:59 AEST 1990
noah at wet.UUCP (Noah Spurrier) writes:
>char *squirl()
>{
> static char *test = NULL;
> free (test);
> test = (char *) malloc (100);
> return (test);
>}
>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);
>Will angry things happen if I try to free(NULL) ?
ANSI C may specify that free(NULL) should work, but for those
people currently not using an ANSI C compiler the following
will also work:
static char *test = (char *) malloc (100);
This obviously wastes time during the first execution, but should work
across all K&R C libraries and ANSI C libraries.
BTW: If the ANSI C library supports this, does this mean that
the "if (test != NULL)" is done by the library which now means that
you'll always use up your run time with this test even if you
know the test isn't needed?
--
___________________________________________________________________
/ Aaron Henley, Motorola Inc. DISCLAIMER: std.disclaimer /
/ Cellular Infrastructure Division UUCP: ...!uunet!motcid!henley /
/__________________________________________________________________/
More information about the Comp.lang.c
mailing list