Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.lang.c Subject: Re: A simple non-portable expression tha Message-ID: <6612@utzoo.UUCP> Date: Tue, 22-Apr-86 19:11:05 EST Article-I.D.: utzoo.6612 Posted: Tue Apr 22 19:11:05 1986 Date-Received: Tue, 22-Apr-86 19:11:05 EST References: <130@brl-smoke.ARPA> Organization: U of Toronto Zoology Lines: 29 > No, the compiler is not free to associate right-to-left in an > expression > long + int + int. > Addition associates left-to-right, and the integral widening > conventions apply, so the middle term must be converted to long > and added to the leftmost term before the rightmost term is > added. The compiler is allowed to reorder this only if it > guarantees the same answer as would be obtained by following > the rules... Sorry, Doug, not so. Not in the draft standard, anyway, unless serious changes have been made since my last copy (November). Yes, there is a statement early on to the effect that "the compiler can do things any way it pleases if the results are the same". However, somewhat later, in C.3, we also find: An expression involving more than one occurrence of the same commutative and associative binary operator (*, +, &, ^, |) may be regrouped arbitrarily... provided the types of the operands or of the results are not changed by this regrouping. Note that no mention is made of the types of intermediate values, unless that ambiguous reference to "results" instead of "result" is meant to imply it. And there is no constraint that the value of the expression be unchanged. -- Support the International League For The Derision Henry Spencer @ U of Toronto Zoology Of User-Friendliness! {allegra,ihnp4,decvax,pyramid}!utzoo!henry