why is free() a void?

Barry Margolin barmar at think.com
Wed Oct 31 04:24:29 AEST 1990


In article <14 at christmas.UUCP> rtm at island.uu.net (Richard Minner) writes:
>void free() is a good example.
...
>I think most large projects would be well advised to
>design a layer on top of the standard library.

But if you're going to use the standard library as a foundation for another
layer, it has to provide decent services to the upper layer.  Void free()
doesn't provide such a service.

Many respondents have explained that free() isn't required to detect
errors.  That's acceptable.  The problem with the ANSI specification is
that free is *prohibited* from returning an error indication that a
portable program can use.  It would have been better if it had been defined
to return an int, with the specification that the implementation is not
required to validate the argument, but if it does so then it may return -1
and set errno if it fails the validation.  This would make systems that are
able to check during free() (such as the debugging malloc libraries that
many systems provide) more useful, as the application can try to recover.


--
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list