|
|
1.1 root 1: From alice!dmr Wed Apr 11 09:08:05 EDT 1990
2:
3: honorp (dmr) Wed Apr 11 01:46:18 1990
4:
5: There is confusion about the rearrangement rules in the K&R 1
6: language and about how ANSI C changed things. The wording in K&R 1
7: wasn't precise enough in any event, but there was also a real
8: change in content.
9:
10: K&R 1 said, "Expressions involving a commutative and associative
11: operator (*, +, |, ^) may be rearranged arbitrarily, even in
12: the parentheses; to enforce a particular order of evaluation
13: an explicit temporary must be used."
14:
15: The exact intent of this statement was no more than this:
16: "A compiler is entitled to regard mathematically commutative
17: and associative operators as computationally commutative and
18: associative."
19:
20: The imprecision of the original statement caused considerable worry,
21: which still persists; for example it could be interpreted as saying that
22: along+ashort+ashort
23: or even
24: (along+ashort)+ashort
25: might add the shorts in short precision before adding the sum to the long.
26: This wasn't the intent, and I don't think it's the practice.
27:
28: X3J11 decided not only to clarify the matter, but also to
29: strengthen the requirements. Its rule is that the value
30: of an expression must be computed as if each subexpression
31: in the parse (including the effects of parentheses) were computed
32: as written. The temporal order of side effects remains undefined.
33:
34:
35:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.