tobold.org

correct • elegant • free

△ Comp.lang.c △

◅ Multiple EOF's when scanning a file.

Book Suggestion ▻

Book Suggestion

In article <891gqv$5a7$1@newsg2.svr.pol.co.uk>,
Stu <stewart@*NOSPAM*proclass.co.uk> wrote:
>What's the general consensus on the use of asserts,

There's a very special feeling you get the first time you change some
code, and an assert in a distant part of the program fails, and you
realise that it just saved you from a painful session with the debugger.

>                                                    as parameter validation
>(value is valid, i.e. between MIN and
>MAX for its type, or is not NULL) and in other areas?

Remember that you must only use assert to test conditions guaranteed
"can never happen" by library interfaces.  Don't get carried away and
use assert to test for return codes that (validly) indicate an error;
nor for user input.

    x = malloc(10);
    assert(x); /* WRONG */

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: Book Suggestion
Date: 24 Feb 2000 15:50:06 -0000
Message-ID: <893k04$1eq$1@ltpcg.star.le.ac.uk>
References: <88nins$j6l$1@nnrp1.deja.com> <88uqd5$90a$1@news6.svr.pol.co.uk>
  <slrn8b6gi1.i06.kaz@ashi.FootPrints.net> <891gqv$5a7$1@newsg2.svr.pol.co.uk>

△ Comp.lang.c △

◅ Multiple EOF's when scanning a file.

Book Suggestion ▻