Mail Archives: djgpp/2000/10/16/03:05:10
ChuckEasttom wrote:
>
<snip Schildt exposé URLs>
> >
>
> Something you seem to miss is that the beauty and power of C is the
> fact that it lends itself to a variety of programming styles. I
> personally liked Schildts books. I have only read three of them but
> the ones I read I liked. They where not perfect, but they where good.
> Appearantly a lot of other people do, since they sell so well.
Yes, they do sell well, don't they? So do horoscopes.
Schildt is probably the primary reason that so many C programmers think
main returns void.
Schildt is probably the primary reason that so many C programmers think
fflush(stdin) is a "neat trick".
Schildt is probably the primary reason that so many C programmers use
gets().
Schildt is probably the primary reason that so many C programmers think
exit(1) is portable.
Schildt is probably the primary reason that so many C programmers don't
understand ISO namespace.
To select a typical example of his handiwork more or less at random,
p550 of "C - The Complete Reference" 2nd edition has the following code:
void enter(void)
{
char s[256], *p;
do {
printf("enter appointment %d: ", spos+1);
gets(s);
if(*s==0) break; /* no entry */
p = malloc(strlen(s));
if(!p) {
printf("out of memory.\n");
return;
}
strcpy(p, s);
if(*s) qstore(p);
} while(*s);
}
Now, structured it ain't, but let's not worry too much about that, when
there's so much else to worry about.
Bug 1: no guarantee that the prompt will be displayed before the input
function is called.
Bug 2: use of gets(). Anyone caring to type in 256 non-'\0' characters
can cause this program to break.
Bug 3: the malloc call is getting one byte too few to store the string,
so the strcpy will cause undefined behaviour.
Bug 4: unnecessary test of *s before qstore call.
Bug 5: unnecessary test of *s in while loop.
5 bugs in 17 lines (including whitespace and curly braces). One bug
every 3.4 lines, in a book which, despite its name, intends to be a
tutorial. Admittedly it's a small sample. Nevertheless, I once made the
mistake of claiming, in comp.lang.c, that there was bound to be at least
one page in the book that didn't have a single mistake on it anywhere,
and Dann Corbit challenged me to produce such a page. I couldn't.
--
Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
66 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (31
to go)
- Raw text -