Just a minor new twist on free()

Charles Tryon bilbo at bisco.kodak.COM
Thu Oct 11 23:42:13 AEST 1990


In <1990Oct10.155448.1465 at Neon.Stanford.EDU>, dkeisen at Gang-of-Four.Stanford.EDU (Dave Eisen) writes:
> In article <11 at christmas.UUCP> rtm at island.uu.net (Richard Minner) writes:
> >In article <8026 at scolex.sco.COM> seanf (Sean Fagan) writes:
> >>And now an ANSI compliant library must have free() check for a NULL
> >>parameter, which means that, instead of 10000 tests, you are now doing 20000
> >>tests.  Yep.  Just love those performance increases, don't you?
> >
> >The ANSI behavior for free() is a good thing.  I don't want to read
> >any more complaints about it ;-)
> 
  ....
> I'd prefer free not check for NULL pointers because I'd rather have 
> my sloppy (and probably incorrect) programming caught by a core dump
> than slipping by untouched. I never check for NULL pointers in library
> routines that I write unless there is a useful action that should be taken
> when that pointer is NULL.

  Wouldn't it be more graceful to check for invalid data (such as, but not
  limited to NULL pointers), and on an error condition print a MESSAGE and
  exit gracefully (perhaps with a core dump to allow a debugger to give you
  trace-back information).  Assuming that a program will crash is a very
  dangerous thing (not to mention, not very friendly), since it might choose
  instead to just hose up memory and continue on as if nothing had happened.
  Remember that YOU probably won't be the only person using your software,
  and other people strongly frown upon unexplained crashes.

> Dave Eisen                      	    Home: (415) 323-9757

--
Chuck Tryon
    (PLEASE use this address, as Kodak foobars one in header!)
    <bilbo at bisco.kodak.com>
    USmail: 46 Post Ave.;Roch. NY 14619                       B. Baggins
    <<...include standard disclamer...>>                      At Your Service

     "Then again, squirrels could be stupid."   (D. Mocsny)



More information about the Comp.lang.c mailing list