Just a minor new twist on free()

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Fri Oct 12 22:30:57 AEST 1990


In article <4d5780ad.20b6d at apollo.HP.COM> blodgett at 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 <stdlib.h>:
> #define free(x) ( (x) ? free(x) : ( (void)0 ) )
> #define free(x) { void * ptr = (x); if ( ptr != NULL ) free(ptr); }

Much better:

  #define free(x) ( ( __frx = x ) , ( __frx ? __frol(__frx) : (void) 0 ) )
  extern void *__frx;
  extern void (*__frol)();

In the library source, undef free, define __frx, and define __frol
initialized to &free.

---Dan



More information about the Comp.lang.c mailing list