Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!uw-entropy!dataio!bright From: bright@Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: return value of free Message-ID: <1849@dataio.Data-IO.COM> Date: 27 Jan 89 18:48:48 GMT References: <287@proton.UUCP> Reply-To: bright@dataio.Data-IO.COM (Walter Bright) Distribution: usa Organization: Data I/O Corporation; Redmond, WA Lines: 26 In article <287@proton.UUCP> proton!nusbaum@ucrmath.ucr.edu (R. James Nusbaum) writes: >What is the story on the return value of free? ANSI C says that the return value of free() is (unfortunately) void. The reason I say unfortunately is that it now can't return an error status. Zortech's free() returns an int which says whether it failed or not. If it failed, this means that either the heap has been corrupted or an attempt was made to free a wild pointer. The proper behavior then is to print a message and abort the program before it crashes. free() cannot guarantee that it'll always detect errors, but it does often enough that this is a valuable feature. You could argue that free() should internally print the message and abort. This is an inferior solution, because the program may need to do some cleanup before it exits, like restoring hooked interrupt vectors and switching the display back to text mode. I intend to leave it this way, and in stdlib.h have something like: #if __STDC__ void #else int #endif free(void *); P.S. I wrote Zortech C.