Error in previous posting
Doug Gwyn
gwyn at smoke.brl.mil
Sat Apr 6 09:32:05 AEST 1991
In article <1991Apr4.160608.13628 at mccc.edu> pjh at mccc.edu (Peter J. Holsberg) writes:
>x[i++] *= y; is treated as
>x[i++] = x[i] * y; instead of
>x[i++] = x[i++] * y;
>Where/how is this described?
>Interestingly, very few textbooks mention it at all, probably because
>they introduce assignment operators before side effects.
Strange -- the first textbook I picked up to check this (K&R2) says
almost precisely the same thing as the C standard. I suggest you
consider using K&R2 (Second Edition of Kernighan & Ritchie's "The C
Programming Language") as your C textbook in place of whatever you
have been using.
In the C standard X3.159-1989, the relevant specification is exactly
where one would think it should be, in section 3.3.16.2 (Compound
Assignment) Semantics. Since it is quite brief and elegant, I'll
quote it here, even though I think you should look at p.50 of K&R2:
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.
More information about the Comp.lang.c
mailing list