Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp
Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!decvax!decwrl!sun!guy
From: guy@sun.uucp (Guy Harris)
Newsgroups: net.lang.c
Subject: Re: C style
Message-ID: <2848@sun.uucp>
Date: Fri, 4-Oct-85 02:40:39 EDT
Article-I.D.: sun.2848
Posted: Fri Oct  4 02:40:39 1985
Date-Received: Sat, 5-Oct-85 14:52:54 EDT
References: <1556@brl-tgr.ARPA> <139200011@uiucdcsb> <309@seismo.CSS.GOV>
Organization: Sun Microsystems, Inc.
Lines: 33

> > For Heaven's sake, the big problem with this code is that the conditional
> > is quite unreadable in in-line code like this.  I'd prefer
> >
> >	while (illegal (ch = getch()))
> >
> > (where "illegal" is defined as a function testing its character
> > argument). 
>
> It may enhance readability, but it's not worthwhile.  You've just managed
> to add a context switch per *character*.  Now, imagine what that's going to
> do to a program like spell.

Yes.  The System V "fgrep" uses a subroutine to do character comparisons.
The 4.2BSD version uses a macro instead.  The 4.2BSD version is
substantially faster.

The function "illegal" in the above example could have been defined as a
macro.  The code calling it would, of course, would have to be rewritten as

	for (;;) {
		ch = getch();
		if (ILLEGAL(ch))
			break;

or somesuch, since the macro uses its argument several times, and thus the
argument can't have side effects.  Mesa, C++, and other languages have the
notion of an "inline function"; when such a function is called, the compiler
doesn't generate a procedure call, but generates code that acts as if the
procedure in question had been called.  In the above example, the code as
written ("while (illegal(ch = getch))") would have compiled into code
equivalent to the macro version.

	Guy Harris