Path: utzoo!attcan!uunet!husc6!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: ANSI, K&R, H&S (was: Re: Just a minor new twist on free()) Message-ID: <27368@mimsy.umd.edu> Date: 2 Nov 90 12:35:34 GMT References: <222@smds.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 73 In article <222@smds.UUCP> sw@smds.UUCP (Stephen E. Witham) writes: >The whole point of the project that led to the [H&S] book was to >seek out the fuzzy edge of C, see what was really happening there, >and FIGURE OUT HOW TO AVOID IT. The book is full of advice like, "Don't >use this feature," or, "Sometimes this doesn't work, sometimes this doesn't >work, so the most conservative and portable way to do it seems to be this..." > >Stephen Clamage tried to make this same point to Dan Bernstein, but slipped >up by talking about "portable" and "enums" in the same sentence. ... Or, to put it another way, if all you have read is K&R I, you might be tempted to write the following fragment for counting vowels: #include main() { char *p, *getword(); int anum, enum, inum, onum, unum, wnum, ynum; anum = enum = inum = onum = unum = wnum = ynum = 0; while ((p = getword()) != NULL) { if (*p == 'c' && strcmp(p, "cwm") == 0) { /* * This English word was imported from Welsh. * It is probably the only one in which w is * a vowel. */ wnum++; continue; } for (;;) { switch (*p++) { case '\0': break; case 'a': anum++; continue; case 'e': enum++; continue; case 'i': inum++; continue; case 'o': onum++; continue; case 'u': unum++; continue; case 'y': ynum++; /* could be a consonant... */ continue; default: continue; } break; } } /* print out results */ . . . This code will compile on some systems, and not on others, because `enum' is only sometimes a keyword. >"The Tao that can be dialed is not a working Tao." ... but if you call this 1-900 number today, at only $1235917/minute ... :-) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris