C question

carl carl at bdaemon.UUCP
Wed Apr 10 01:27:17 AEST 1985


Please, let us stop this discussion of side effects right NOW.  It has been
beaten to death before and is pointless.  Instead, read page 50 of K&R,
where the following sentences can be found:

"In any expression involving side effects, there can be subtle dependencies
on the order in which variables taking part in the expression are stored.
One unhappy situation is typified by the statement

	a[i] = i++;

The question is whether the subscript is the old value of i or the new.
The compiler can do this in different ways, and generate different answers
depending on its interpretation.  When side effects (assignment to actual
variables) takes place is left to the discretion of the compiler, since the
best order strongly depends on machine architecture.
	The moral of this discussion is that writing code which depends on
order of evaluation is a bad programming practice in any language."

Carl Brandauer
daemon associates, Inc.
1760 Sunset Boulevard
Boulder, CO 80302



More information about the Comp.lang.c mailing list