Tim Rentsch said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Pilcrow said:
free(s);
s = malloc(width+1);
assert(s != NULL);
Bad idea. Use assertions only when the program is incorrectly written.
Using assertions inappropriately means the program is incorrectly
written, wouldn't you say? ;) ;) ;)
Aye! Lousy wording, wasn't it? I should have written something like:
Use assertions only to test assumptions in your code that must be true if
the program is correctly written. For example, if a particular function is
inside a data "firewall" such that it is *impossible* for it to be called
with invalid data, then it's okay (and in fact a good idea) to write
something like:
assert(temperature MELTING_POINT &&
temperature < BOILING_POINT);
What we're actually testing here is not the data, but the "firewall".
The assertion would be inappropriate, however, in the "firewall" code
itself. For example, if a user has just typed this stuff in, you wouldn't
want to bomb out if he typo'd; you'd just want to prompt him with an error
message and a request to re-enter the data.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999