why is free() a void?

Robert E. Lancia rob at meaddata.com
Thu Oct 25 00:20:58 AEST 1990


As the subject says, I'm curious as to why free() does not return a value.
(At least on our SPARCstations, SUN 3's and 4's, RT's and Sequent, free()
is a void function.)

It seems to me that it could pass back some useful information, especially
if there was a problem.  Was the pointer NULL, or an invalid address??
Was the memory not allocated by malloc() or it's siblings??

>From K&R 2, page 252:

    "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??


Any ideas?
--
|Robert Lancia                      | Mead Data Central
|(513) 297-2560                     | Data Services Division
|rob at pmserv.meaddata.com            | P.O. Box 308
|...!uunet!meaddata!pmserv!rob      | Dayton, Ohio  45401



More information about the Comp.lang.c mailing list