Newsgroups: comp.lang.c Path: utzoo!sq!msb From: msb@sq.sq.com (Mark Brader) Subject: Re: () ignored in some expressions Message-ID: <1990Apr11.202241.12258@sq.sq.com> Reply-To: msb@sq.com (Mark Brader) Organization: SoftQuad Inc., Toronto References: <48079@lanl.gov> <16414@haddock.ima.isc.com> <628@nlsun1.oracle.nl> Date: Wed, 11 Apr 90 20:22:41 GMT As has been explained, in ANSI C (x+y)+z is required to evaluate x+y first if you can tell the difference, but before ANSI C, it could begin by evaluating x+z or y+z, and similarly for other commutative and associative operators. In my opinion this was a good feature and I was sorry to see X3J11 change it. It is quite common for a macro to expand to something like like ((x)+1)+((y)+1), and we would usually like to treat this as x+y+2 even though this may cause an overflow for certain values of x and y, where the original expression would not overflow. In the rare cases where the sequence of operations is critical, the expression can always be broken up. However, the floating-point users were also right to want precise control over the sequence of operations, when working with floating types. With these types it is more common for the sequence to be critical. So what I would have liked to see go into the standard was the old rule about commutative and associative operators, plus one more sentence: "Arithmetic operators with operands of floating type are not associative." This is, of course, the truth. (I did propose this compromise to X3J11, but too late.) -- Mark Brader "It is impractical for the standard to attempt to SoftQuad Inc., Toronto constrain the behavior of code that does not obey utzoo!sq!msb, msb@sq.com the constraints of the standard." -- Doug Gwyn This article is in the public domain.