🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1919

Re: ANSI, K&R, H&S (was: Re: Just a minor new twist on free())

#1919
From: Chris Torek
Date: Fri, 02 Nov 1990 12:35
73 lines
2351 bytes
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 <stdio.h>

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
Technical Details
Message-ID: <27368@mimsy.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!purdue!haven!mimsy!chris
References: <PDS.90Oct8101336@lemming.webo.dg.com> <222@smds.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <PDS.90Oct8101336@lemming.webo.dg.com> <222@smds.UUCP>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 73