Message-ID: <39EAA40B.31B0CA89@eton.powernet.co.uk> Date: Mon, 16 Oct 2000 07:45:31 +0100 From: Richard Heathfield Organization: Eton Computer Systems Ltd X-Mailer: Mozilla 4.6 [en-gb]C-CCK-MCD NetscapeOnline.co.uk (WinNT; I) X-Accept-Language: en-GB,en MIME-Version: 1.0 Newsgroups: alt.comp.lang.learn.c-c++,comp.os.msdos.djgpp,comp.programming Subject: Re: Undertaking a programming journey References: <8scg36$gsm$1 AT nnrp1 DOT deja DOT com> <39E9CF07 DOT 785C0C0F AT eton DOT powernet DOT co DOT uk> <8scls9$kth$1 AT nnrp1 DOT deja DOT com> <39E9FAD5 DOT DE1FDAE4 AT eton DOT powernet DOT co DOT uk> <8sdrub$h7u$1 AT nnrp1 DOT deja DOT com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 195.60.5.69 X-Trace: 16 Oct 2000 07:49:21 +0100, 195.60.5.69 Lines: 73 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com ChuckEasttom wrote: > > > > > 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)