Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA
Path: utzoo!linus!philabs!cmcl2!seismo!brl-tgr!tgr!COTTRELL@BRL.ARPA, JAMES
From: COTTRELL@BRL.ARPA, JAMES
Newsgroups: net.lang.c
Subject: Assignment in Conditionals
Message-ID: <509@brl-tgr.ARPA>
Date: Thu, 8-Aug-85 13:21:12 EDT
Article-I.D.: brl-tgr.509
Posted: Thu Aug  8 13:21:12 1985
Date-Received: Sun, 11-Aug-85 04:27:42 EDT
Sender: news@brl-tgr.ARPA
Lines: 57

/*
> 3) Is there really much to be gained by using assignment within
>    a boolean expression, for example, is
>
>	if ((fp = fopen("foo", "r") == NULL) {

Darn tootin! Consider the common case of:

	while ((c = getchar()) != EOF) {
		process(c);
	} /* AT EOF */

Now how do you write it without the assignment?

	1)	c = getchar();
		while (c != EOF) {
			process(c);
			c = getchar();
		} /* AT EOF */

	2)	for (c = getchar(); c != EOF; c = getchar()) {
			process(c);
		} /* AT EOF */

	3)	do {	c = getchar();
			if (c != EOF)
				process(c);
		} while (c != EOF);

	4)	for(;;) {
			c = getchar();
			if (c == EOF)
				break;
			process(c);
		}

Get the idea? Either 1) you have to duplicate the initial assignment,
2) you have to duplicate the test, or 3) you have to use TWO control
struxures (three if you count break) in a non-obvoius way where one
would do. This is a very simple example, but things get quite 
complicated if either the assignment or the processing is expanded 
inline.

There is no reason why assignment should not return a value. LISP & APL
both do. An experienced programmer in either language can handle that.
In LISP, even conditionals & loops return values, & I see no reason why
they couldn't have been designed that way in C.

The penalty for excluding assignment in conditionals is contortions
in the control struxures.

If you can't stand the heat, stay out of the compiler.
Stroll around the grounds until you feel at home.

	jim		cottrell@nbs
*/
------