all this evaluation order brouhaha
Philip Kos
phil at osiris.UUCP
Thu Oct 23 23:35:00 AEST 1986
Apologies if this extract has already been posted by someone. We
have a chronic newsfeed problem which causes us to miss (by my best
estimate) about a quarter of all articles posted.
Anyway, a part of the "standard" UNIX documentation includes an
overview/tutorial for the ``lint'' program checker, written by Steve
Johnson himself. On page 6 (under the heading "Multiple Uses and
Side Effects"), is the following (REPRINTED WITHOUT PERMISSION, so
I hope the Copyright Police aren't watching :-):
"In complicated expressions, the best order in which to evaluate
subexpressions may be highly machine dependent. For example, on
machines (like the PDP-11) in which the stack runs backwards, func-
tion arguments will probably be best evaluated from right-to-left;
on machines with a stack running forward, left-to-right seems most
attractive. Function calls embedded as arguments of other functions
may or may not be treated similarly to ordinary arguments. Similar
issues arise with other operators which have side effects, such as
the assignment operators and the increment and decrement operators.
[Now here comes the good part - pk]
"In order that the efficiency of C on a particular machine not be
unduly compromised, the C language leaves the order of evaluation
of complicated expressions up to the local compiler, and, in fact,
the various C compilers have considerable differences in the order
in which they will evaluate complicated expressions. In particular,
if any variable is changed by a sided effect, and also used else-
where in the same expression, the result is explicitly undefined."
Disclaimers: "UNIX" is a trademark of somebody from New Jersey,
maybe Bruce Springsteen, I don't know. "Lint" is a good thing if
you use it; I can think of at least one major software company who
obviously doesn't know it exists.
Phil Kos ...!decvax!decuac
The Johns Hopkins Hospital > !aplcen!osiris!phil
Baltimore, MD ...!allegra!umcp-cs
"What do they do in Mississippi,
When skies are drippy?" - A. N. F. O. Singer
More information about the Comp.lang.c
mailing list