why is free() a void?

Doug Gwyn gwyn at smoke.brl.mil
Wed Nov 7 21:28:08 AEST 1990


In article <1990Oct30.172429.10055 at Think.COM> barmar at think.com (Barry Margolin) writes:
>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.

(a) The C standard is based on existing practice, and existing free() does
not return a validation value.

(b) It would be impossible to completely verify that the pointer passed to
free() is appropriate.

(c) It would be expensive to partially verify that the pointer passed to
free() is appropriate.

(d) It would be silly to write code that relied on this run-time validation
if it's not guaranteed to be done anyway.



More information about the Comp.lang.c mailing list