short circuit evaluation
john at viper.UUCP
john at viper.UUCP
Mon Mar 2 19:59:20 AEST 1987
In article <4211 at utcsri.UUCP> greg at utcsri.UUCP (Gregory Smith) writes:
>
>It is worth noting at this point that the parentheses '(' and ')' serve
>only in the process of converting a linear expression to a tree. Thus
>(a+b)*c is different from a+b*c but a+(b+c) can be treated the same as
>(a+b)+c. Simply allow your tree to contain a node which forms the sum of
>its three, equally ranked, children, and throw in the fact that
>redundant ()'s grow in C like mushrooms. Then a+(b+c) should be treated
>as a+b+c or SUM(a,b,c). ( I know, there are overflow considerations).
>
>----------------------------------------------------------------------
>Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg
>Have vAX, will hack...
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 at viper.UUCP)
Software Consultant - DynaSoft Systems
UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john
More information about the Comp.lang.c
mailing list