Complexity of reallocating storage (was users command crap)

Tim McDaniel mcdaniel at adi.com
Wed Feb 13 09:39:40 AEST 1991


mike at BRL.MIL (Michael John Muuss <mike>) writes:

   Having programs not checking the error returns can make the job of
   troubleshooting and repairing malfunctions much more difficult.
   Yes, error checking can demand 3-4 times as much code as the actual
   task at hand.  For essential systems programs, and criticial user
   applications, the error checking is well worth it.

A number of places, including Applied Dynamics (plug plug), use an
exception-handling library.  If a function fails, it raises an
exception, causing the invocation of any code-specific exception
handlers (and, in some implementations, outputs a message if not
handled).  Many implementations use preprocessor trickery at some
point, to make the code look nice.

There's an incredible feeling of freedom in simply writing

    buf = MEMmalloc(STlen(s) + 1);

and knowing that the function won't return if it fails, and to write
the one line

    EMMfatal("MEMmalloc", MEMoutOfMemory, "");

to do everything needed to wrap up the program with an informative
message.  We have much more robust code as a result of such a library.
Also, error handling is centralized, so all the messages have the same
appearance, and it's easy to redirect them to a new destination.

This topic has been discussed in comp.lang.c before, and it's not
relevant to C per se anyway, so I won't go into more details.

--
"I'd hang you from my nipples ... but it would shock the children."

Tim McDaniel                 Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Internet: mcdaniel at adi.com                UUCP: {uunet,sharkey}!amara!mcdaniel



More information about the Comp.bugs.4bsd.ucb-fixes mailing list