Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!abvax!iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) Newsgroups: comp.lang.c Subject: Re: Just a minor new twist on free() Message-ID: <1282.270b315c@iccgcc.decnet.ab.com> Date: 4 Oct 90 17:55:55 GMT References: <7365@darkstar.ucsc.edu> Lines: 29 In article <7365@darkstar.ucsc.edu>, funkstr@ucscb.ucsc.edu (Larry Hastings) writes: > [ ...] > > #define smart_free(x) { if (x != NULL) { free(x); x = NULL; } } <> How quickly they forget... From the thread on how to do if's in a macro: #define smart_free(x) ( ((x) !=NULL) && (free(x),0) ) From the thread on the meaning of NULL: #define smart_free(x) ( ((x) != 0) && (free(x),0) ) which collapses to #define smart_free(x) ( (x) && (free(x),0) ) Now, somebody please remind ME: Is "(free(x),0)" what the netsters came up with as the best wat to do a void function, or should it be something else? BTW, I'm not taking sides on whether one _should_ test the value of x before calling free(x). My point is just that I hate to see all the other good comments about macros and NULL disappear into oblivion. The above is my own opinion and not attributable to any other person or organization. email: browns@iccgcc.decnet.ab.com Stan Brown, Oak Road Systems, Cleveland, Ohio, U.S.A. (216) 371-0043