Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!samsung!umich!yale!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: why is free() a void? Message-ID: <1990Oct30.172429.10055@Think.COM> Date: 30 Oct 90 17:24:29 GMT References: <1749@meaddata.meaddata.com> <1990Oct25.152057.23024@zoo.toronto.edu> <14@christmas.UUCP> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 26 In article <14@christmas.UUCP> rtm@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@think.com {uunet,harvard}!think!barmar