Compound Assignments (was Re: Another <sigh> error!)

Pete Holsberg pjh at mccc.edu
Tue Apr 9 03:49:51 AEST 1991


In article <1991Apr6.195901.25255 at dvorak.amd.com> tim at amd.com (Tim Olson) writes:
=In article <1991Apr4.205257.15205 at mccc.edu> pjh at mccc.edu (Peter J. Holsberg) writes:
=| 	x *= y;
=| 
=| has the "x" part evaluated twice, as in
=| 
=| 	x = x * y;
=
=In the second example, "x" is not evaluated twice -- it is evaluated
=only once, just as in the first example.  The standard says just this
=in 3.3.16.2 (Compound assignment):
=
=  Semantics
=
=	A compound assignment of the form E1 op= E2 differs from the
=	simple assignment expression E1 = E1 op (E2) only in that the
=	lvalue E1 is evaluated only once.

The reference to E1 is ambiguous, as is the entire statement, IMHO. 
*Which* E1 is evaluated "only once", the E1 op= E2 one or the other? 
Does it follow that the remaining one is evaluated twice?  not at all?

Thanks,
Pete
-- 
Prof. Peter J. Holsberg      Mercer County Community College
Voice: 609-586-4800          Engineering Technology, Computers and Math
UUCP:...!princeton!mccc!pjh  1200 Old Trenton Road, Trenton, NJ 08690
Internet: pjh at mccc.edu	     Trenton Computer Festival -- 4/20-21/91



More information about the Comp.lang.c mailing list