Xref: utzoo comp.lang.c:32814 comp.std.c:3749 Path: utzoo!attcan!uunet!crdgw1!uakari.primate.wisc.edu!aplcen!haven!udel!gdtltr From: gdtltr@freezer.it.udel.edu (Gary Duzan) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Just a minor new twist on free() Message-ID: <33208@nigel.ee.udel.edu> Date: 12 Oct 90 01:42:45 GMT References: <4d5780ad.20b6d@apollo.HP.COM> Sender: usenet@ee.udel.edu Followup-To: comp.lang.c Organization: Brain Dead Innovations (BDI) Lines: 30 Nntp-Posting-Host: 128.175.50.15 In article <4d5780ad.20b6d@apollo.HP.COM> blodgett@apollo.HP.COM (Bruce Blodgett) writes: => =>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). Both will also have the property of recursively expanding free() forever. Better to call it something else. Your cpp will thank you for it. Gary Duzan Time Lord Third Regeneration -- gdtltr@freezer.it.udel.edu _o_ -------------------------- _o_ [|o o|] An isolated computer is a terribly lonely thing. [|o o|] |_O_| "Don't listen to me; I never do." -- Doctor Who |_O_|