Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!island!grenada!christmas!rtm From: rtm@christmas.UUCP (Richard Minner) Newsgroups: comp.lang.c Subject: Re: Just a minor new twist on free() Summary: accepting NULL without complaint is a GOOD thing Message-ID: <10@christmas.UUCP> Date: 5 Oct 90 04:39:16 GMT References: <7365@darkstar.ucsc.edu> <1990Oct02.132313.6659@virtech.uucp> Reply-To: rtm@island.uu.net (Richard Minner) Organization: Island Graphics, Sacramento, California Lines: 35 I personally like all `destroy_thing()' functions to quietly accept a non-existent (NULL) `thing'. (After all, what I want is for the thing to be gone, and if it's already not there, that's fine with me. :-) I find all the `if (ptr)' tests cluttersome (not a real word). If the thing really should not be null, I'll do an assert(thing) before destroying it. One particular usage this model simplifies is the multiple create, e.g: thing1 = create_thing(); thing2 = create_thing(); ... thingN = create_thing(); if (!thing1 || !thing2 || ... || !thingN) { destroy_thing(thing1); ... destroy_thing(thingN); } which to me reads nicely as: "try to get things, if didn't get them all, get rid of any you got." As a final bit, I second the recommendation of using your own `shell' functions around the standard malloc family, rather than macros; it's more flexible (as noted by ??, sorry) and the overhead of the `extra' call is (almost always) insignificant compared to the work the library functions will be doing. -- Richard Minner || {uunet,sun,well}!island!rtm (916) 736-1323 || || Island Graphics Corporation Sacramento, CA ||