Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!bellcore!faline!ulysses!gatech!seismo!ut-sally!ut-ngp!infotel!pollux!bobkat!m5d From: m5d@bobkat.UUCP Newsgroups: comp.lang.c Subject: Re: short circuit evaluation Message-ID: <673@bobkat.UUCP> Date: Wed, 4-Mar-87 17:08:03 EST Article-I.D.: bobkat.673 Posted: Wed Mar 4 17:08:03 1987 Date-Received: Fri, 6-Mar-87 23:13:54 EST References: <844@wanginst.EDU> <4700004@uiucdcsm> <4211@utcsri.UUCP> <609@viper.UUCP> Reply-To: m5d@bobkat.UUCP (Mike McNally (dlsh)) Organization: Digital Lynx, Inc; Dallas, TX Lines: 60 In article <609@viper.UUCP> john@viper.UUCP (John Stanley) writes: > >The example Greg provides here is misleading. > >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.......... > > Since there is additional, undesireable, and unnecessary overhead in the >detection of this SUM(a1,a2,a3...,aN) special case, and since there appears >to be little or no advantage to doing so (you have to add them up in -some- >order, you might as well let the programmer decide as anyone), why bother? > >--- >John Stanley (john@viper.UUCP) >Software Consultant - DynaSoft Systems >UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john Sorry, but the compiler writer DOES have the right to use algebraic manipulation to improve code. Why? Because the specification of the language says so. There is some difference between "a + (b + c)" and "(a + b) + c": + + / \ / \ a + + c / \ / \ b c a b A typical code generation scheme will prefer one to the other (one saves a register). What happens in other languages (like FORTRAN) if a programmer doesn't want code re-arranged? At least in C, the compiler is not supposed to mess with stuff across statement boundaries. In a language like FORTRAN or Pascal, the compiler is liable to do common subexpression elimination across an entire basic block (or maybe even globally), not to mention loop unravelling, code hoisting, induction variable elimination, and removal of dead code (a real bad one for you device driver fans). Since lots of people seem outraged at the liscense given to C compilers, perhaps they should give examples of mechanisms which allow optimization to be prevented in other languages. I would hope that such mechanisms are portable. -- Mike McNally, mercifully employed at Digital Lynx --- Where Plano Road the Mighty Flood of Forest Lane doth meet, And Garland fair, whose perfumed air flows soft about my feet... uucp: {texsun,killer,infotel}!pollux!bobkat!m5d (214) 238-7474