[comp.lang.c] Error in previous posting

pjh@mccc.edu (Peter J. Holsberg) (04/05/91)

The other day I posted a request for information about how the standard
describes the behavior of assignment operators when side effects are
involved, but posted an incorrect example.  Here's a correct example and
a repost:

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.

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@mccc.edu	     Trenton Computer Festival -- 4/20-21/91

gwyn@smoke.brl.mil (Doug Gwyn) (04/06/91)

In article <1991Apr4.160608.13628@mccc.edu> pjh@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.