short circuit evaluation

drw at cullvax.UUCP drw at cullvax.UUCP
Thu Mar 12 05:30:53 AEST 1987

john at 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..........

Read the opening paragraphs of section 3.3 of X3J11.  The compiler is
allowed to re-associate multiples uses of *, +, &, ^, and |.  If you
want to prevent this, you have to write:

	+(a+b) + c, etc.

The parentheses you wrote aren't explicit cues to the compiler, by
definition.  (*Why* X3J11 did this is another question...)

Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw at
Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)

More information about the Comp.lang.c mailing list