free (NULL);

Blair P. Houghton bph at buengc.BU.EDU
Wed May 9 06:24:56 AEST 1990


In article <1194 at wet.UUCP> noah at wet.UUCP (Noah Spurrier) writes:
>
>Is there anything wrong with freeing a NULL? pointer? I have a function that

In ANSI C, doing `free(ptr)', "if ptr is a NULL pointer, no action
occurs" (quoted from X3.159-1989).

Most current free(3) manual pages seem to ignore this bit of
semantics, though you might get stuck on things like "the
argument to free is a pointer to a block of memory previously
allocated by malloc()."

ANSI instead says that if it doesn't match a *alloc'ed pointer
it has undefined consequences, except of course for the explicit
case where the pointer is NULL.

				--Blair
				  "Let's get Mikey to program it.
				   Yeah, he hates everything..."



More information about the Comp.lang.c mailing list