short circuit evaluation & side-effects

Henry Spencer henry at utzoo.UUCP
Sat Feb 7 04:05:03 AEST 1987


>     As I understand it this means the results of:
> (1)	x = *i++ * (1 - *i++);
> is unpredicatable.  ANSI added the unary + to fix this (as well as for
> numerical analysis (i.e. floating point) calculations) so that:
> (2)	x = +(*i++ * (1 - *i++));
> does what one would expect...

Hold it, you are attributing incorrect properties to unary +.  It does
nothing of the kind.  The sole and only relevant property of unary + is
that it inhibits regrouping of expressions, e.g. "a + +(b + c)" is
guaranteed to add b and c and then add the result to a, whereas "a+(b+c)"
might add a to c and then add the result to b.  Unary + does *not* define
a "sequence point" and hence does not promise anything about the timing of
side effects.
-- 
Legalize			Henry Spencer @ U of Toronto Zoology
freedom!			{allegra,ihnp4,decvax,pyramid}!utzoo!henry



More information about the Comp.lang.c mailing list