Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: C & fp (really parens) Message-ID: <5739@brl-smoke.ARPA> Date: Thu, 9-Apr-87 18:05:23 EST Article-I.D.: brl-smok.5739 Posted: Thu Apr 9 18:05:23 1987 Date-Received: Sat, 11-Apr-87 11:53:31 EST References: <6800@brl-adm.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 48 In article <6800@brl-adm.ARPA> dsill@NSWC-OAS.arpa writes: >Doug Gwyn wrote: >>... However, the dpANS for C has not changed >>the significance of parentheses; C compilers have always been allowed to >>reorder theoretically-commutative and -associative operations. >>... > >From K&R, page 185: >"Expressions involving a commutative and associative operator (*, +, &, |, ^) > may be rearranged arbitrarily, even in the prescence of parentheses; to force > a particular order of evaluation an explicit temporary must be used." > >This implies that when these operations aren't commutative AND associative, >as in floating point, the expressions can't be reordered. Wrong! That is why I was careful to use the qualifier "theoretically-". The abstract arithmetic definition of * and + for all numbers in C IS associative and commutative. It is not intended that machine quirks that cause deviation from the theoretical model in practice somehow cancels the model -- the programmer is not expected to have to take specific machine properties into account in order to determine whether * and + are considered associative and commutative; they are announced to be such for purposes of operation reordering by K&R (and the dpANS). > If this is the >case, what is the unary + needed for if it was added for the benefit of >"numeric" programmers? Unary plus was originally added for "symmetry" with unary minus. It was only later when the request for a way to force evaluation order in expressions was considered that it was observed that unary plus happens to have that nice effect. > Are there compilers that are reordering expressions >with (*, +, &, |, ^) even when they aren't supposed to? There is no such thing as a time when "they aren't supposed to" (if sequence points, volatile data, or other such subtleties are not involved). In fact there are many C compilers that rearrange such expressions, as they have always been permitted to do. >Given that a means for forcing the compiler to respect parentheses is needed, >couldn't something less syntactically "tacky" than the unary + have been found? >I don't think it's intuitive or obvious. Many people would agree that it's a bit kludgy, but since the facility was added anyway for other (not necessarily terrific) reasons and has the desired effect, there is no need to invent anything more for this.