Unary plus ( + )

Michael Meissner meissner at rtp47.UUCP
Wed Aug 7 01:13:46 AEST 1985


In article <177 at hoqam.UUCP> twb at hoqam.UUCP (BEATTIE) writes:
>
>I was under the impression that the parentheses already guaranteed
>grouping. Do any/some/most/all compilers add a and b and then c?
>When is (a+(b+c)) not equal to ((b+c)+a)?
>

To quote K&R, page 185:

	Expressions involving a commutative and associative operator
	(*, +, &, |, ^) may be rearranged arbitrarily, even in the
	presence of parentheses; to force a particular order of eval-
	uation, an explicit temporary must be used.

Thus, (2.0 + (3.0E30 + (-3.0E30))), currently may be reordered to:
((2.0 + 3.0E30) + (-3.0E30)).



More information about the Comp.lang.c mailing list