why is free() a void?
Dave Eisen
dkeisen at Gang-of-Four.Stanford.EDU
Thu Oct 25 07:19:05 AEST 1990
In article <1749 at meaddata.meaddata.com> rob at pmserv.meaddata.com writes:
>
>As the subject says, I'm curious as to why free() does not return a value.
>
> "void free(void *p)
> ... p MUST be a pointer to space previously allocated by calloc,
> malloc, or realloc." (Emphasis on MUST by me.)
>
>What happens if p WASN'T allocated as it should've been?? How do we know
>there was a problem?? Is there really a problem??
>
There most certainly is a problem, free can do all kinds of damage if it
is passed a pointer to (for instance) static memory. Most frees don't check
if the address they are passed makes sense for a free call, most frees
have no way of doing this even if they wanted to. So it is up to the
programmer to be sure that the memory to be freed was obtained from
malloc or its cousins.
--
Dave Eisen Home: (415) 323-9757
dkeisen at Gang-of-Four.Stanford.EDU Office: (415) 967-5644
1447 N. Shoreline Blvd.
Mountain View, CA 94043
More information about the Comp.lang.c
mailing list