Expression sequencing query

Chris Torek chris at umcp-cs.UUCP
Thu Oct 9 21:32:21 AEST 1986


In article <160 at geac.UUCP> len at geac.UUCP (Leonard Vanek) writes:
>... I agree that it is asking for trouble to mix
>side effects in with complicated expressions, [but] I still believe
>that it is a pity that C (even Ansi C) does not even let the
>programmer tell it what order is desired by the use of parentheses!
>To ignore parentheses in determining the evaluation order (i.e.
>(a+b)+c does not guarantee that a and b are added first) causes
>problems with round off errors, not just side effects -- and is
>totally counter-intuitive.

If you want `a+b' to be done first, then `result + c', use

	result = a + b;
	result += c;

The solution is trivial, and the `problem' is well documented.  To
those to whom parentheses directly determine order of evaluation,
I suppose this is indeed troublesome.  As for myself, I never expect
parentheses to do more than override default precedence, so it is
not `totally counter-intuitive' to me.  Even in Fortran I (where,
I believe, the language specification says that (A+B)+C is requires
doing A+B first, then result+C) I would write

	RESULT = A + B
	RESULT = RESULT + C

---if that were what I meant.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list