Xref: utzoo comp.lang.c:32797 comp.std.c:3746 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!apollo!blodgett From: blodgett@apollo.HP.COM (Bruce Blodgett) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Just a minor new twist on free() Message-ID: <4d5780ad.20b6d@apollo.HP.COM> Date: 11 Oct 90 22:55:00 GMT References: Sender: root@apollo.HP.COM Lines: 17 In-reply-to: pds@lemming.webo.dg.com's message of 8 Oct 90 14:13 GMT If you are trying to compile code which may call free() with a NULL argument, and use an implementation of free() that does not handle NULL gracefully, try adding one of the following to : #define free(x) ( (x) ? free(x) : ( (void)0 ) ) or #define free(x) { void * ptr = (x); if ( ptr != NULL ) free(ptr); } The former has the side-effect of evaluating the argument to free() twice. The latter is a statement rather than an expression of type void, and therefore wouldn't work if someone tried to embed a call to free() in an expression (there are not many uses for subexpressions of type void). Bruce Blodgett blodgett@apollo.hp.com (508) 256-0176 x4037