Just a minor new twist on free()

Stan Brown, Oak Road Systems browns at iccgcc.decnet.ab.com
Fri Oct 5 03:55:55 AEST 1990


In article <7365 at darkstar.ucsc.edu>, funkstr at ucscb.ucsc.edu (Larry Hastings) writes:
> [ ...]
> 
> #define smart_free(x) { if (x != NULL) { free(x); x = NULL; } }

<<sigh>>  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 at iccgcc.decnet.ab.com
Stan Brown, Oak Road Systems, Cleveland, Ohio, U.S.A.    (216) 371-0043



More information about the Comp.lang.c mailing list