Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-lcc!styx!ames!ucbcad!ucbvax!decvax!decwrl!hplabs!sdcrdcf!psivax!nrcvax!sdd!root From: root@sdd.UUCP (Root) Newsgroups: comp.lang.c Subject: Re: short circuit evaluation Message-ID: <379@sdd.UUCP> Date: Sat, 7-Mar-87 12:51:58 EST Article-I.D.: sdd.379 Posted: Sat Mar 7 12:51:58 1987 Date-Received: Mon, 9-Mar-87 19:03:05 EST References: <844@wanginst.EDU> <4700004@uiucdcsm> <4211@utcsri.UUCP> <609@viper.UUCP> Reply-To: root@sdd.UUCP (Root) Organization: Software Design & Development Corp, Camarillo, CA Lines: 37 In article <609@viper.UUCP> john@viper.UUCP (John Stanley) writes: > >If you have three expressions: > 1: a+b+c > 2: (a+b)+c > 3: a+(b+c) >all three of them should not be evaluated the same way. Greg implys that >they should be. This is not so. When an equation contains '(' and ')' >it intentionaly (and explicitly) defines the parse tree structure that will >result. The statement "redundant ()'s grow in C like mushrooms" may be true, >but it doesn't give anyone the right to arbitrarily ignore explicit cues >to the compiler. When I don't care, I don't use them. When I do, I do >so for a reason.......... NO!!!! The new DRAFT ANSI standard explicitly says: "An expression involving more than one occurance of the same cummutative and associtive binary operator (*, +, &, ^, |) may be regrouped arbitrarily, EVEN IN THE PRESENCE OF PARENTHESES, provided the types of the operands or of the results are not changed by this regrouping. To force a particular grouping of operations, either the value of the expression to be grouped may be explicitly assigned to an object, or grouping parentheses may be preceded by a unary plus operator." Therefore if one desires to explicitly specify an order, in the new ANSI standard one can use a unary plus operator as follows: 1: +(a + b) + c 2: a + (+(a + b)) This should guarantee the evaluation order! Daniel Corbett Software Design & Development Corp 360 Mobil, Suite 103 Camarillo, CA 93010