tobold.org

correct • elegant • free

△ Comp.lang.c △

◅ Book Suggestion

Free() memory?? ▻

What is the reason so many coders don't check return values ?

In article <896srj$aar$1@nnrp1.deja.com>,
Malcolm  <malcolm_mclean@my-deja.com> wrote:
>One point I made was that most pointer dereferencing is done in loops (very
>often you will use a pointer to step through an array, most code is probably
>executed in some sort of loop anyway). If the first illegal write doesn't
>crash the computer, the next one probably will.

Note the hedging in this last sentence: "if... probably".

And compare it with the very next sentence:

>If you know that illegal memory writes will cause a crash you don't need to
>expend effort avoiding them - simply running the program will reveal the
>problem.

By your own admission, you don't *know* that illegal memory writes will
cause a crash. So at very best simply running the program will only
*probably* reveal the problem.

(And of course, for anything other than the smallest programs, there is
no "simply" running: test suites have to work very hard to get anything
near complete code coverage.)

>         If you think that illegal writes are liable to cause mysterious
>malfunctions in unrelated parts of the program they must be avoided at all
>costs - including the cost of doing things like dry-running code by peers at
>greatly increased programming time.

I once spent many hours spread over several weeks trying to find the
cause of a mysterious malfunction.  Needless to say, it eventually
turned out to be caused by an illegal write in an unrelated part of the
program.  (It didn't even take me very long to conclude that it must be
an illegal write, but finding where it came from was extremely hard and
not fun.)

I was lucky in several respects: my program was not critical (although
it was important, especially to me!); it was not a commercial effort, so
there was no time pressure; the malfunction was reproducible; and when
I found the right tool (in this case ElectricFence), I found the cause
quickly.

>I don't think there is such a thing as "bug-proofing". Generally what people
>call "bug-proofing" means "mask errors in the input".

I've read a number of books on bug-proofing, and tried to apply their
techniques in my own programming.  The basic idea is to detect errors:
handling them if they come from user input (or a library over which you
have no control), and reporting them if they come from other parts of
the program.

Tim.
--
Tim Goodwin   | "If you don't know what closures are, you probably don't
Leicester, UK | want to know what closures are." -- Larry Wall

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.lang.c
Subject: Re: What is the reason so many coders don't check return values ?
Date: 28 Feb 2000 11:16:14 -0000
Message-ID: <89dlek$93n$1@ltpcg.star.le.ac.uk>
References: <2Kfo4.3332$lK6.70814@iad-read.news.verio.net>
  <38ACB9DA.71D6D60F@worldnet.att.net> <896np5$6jr$1@eskinews.eskimo.com>
  <896srj$aar$1@nnrp1.deja.com>

△ Comp.lang.c △

◅ Book Suggestion

Free() memory?? ▻