Compound Assignments (was Re: Another <sigh> error!)
Tim Olson
tim at proton.amd.com
Wed Apr 10 00:51:17 AEST 1991
In article <1991Apr7.185259.12709 at druid.uucp> darcy at druid.uucp (D'Arcy J.M. Cain) writes:
| In article <1991Apr6.195901.25255 at dvorak.amd.com> Tim Olson writes:
| >| x *= y;
| >| 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):
| > 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.
|
| Huh? Am I missing something or does that say that the two expressions
| *ARE* evaluated differently?
Yes, the two expressions you show are evaluated differently. I think
the confusion here is that the two expressions you show aren't the two
original expressions I was talking about -- they were (from the
original article):
| x[i++] *= y;
|
| has the "x[i++]" part evaluated only once, while an expression such as
|
| x *= y;
|
| has the "x" part evaluated twice, as in
Try substituting these two expressions into the discussion above, it
should make more sense.
--
-- Tim Olson
Advanced Micro Devices
(tim at amd.com)
More information about the Comp.lang.c
mailing list