Topic: Operator comma
Author: "Pierre D nomm e" <denommee@microtec.net>
Date: 1998/07/17 Raw View
James Kuyper wrote:
> Wrong. The value of a ',' expression is the value of the second
> assignement expression.
>
> > 1.
> > int x =3D0;
> > x=3D4,x++,x++;
>
> x ends up with a value of 1.
My copy of the standard disagree,
Except where noted, the order of evaluation of operands of individual
operators and subexpressions of individual expressions, and the order
in which side effects take place, is unspecified. Between the previ-
ous and next sequence point a scalar object shall have its stored
value modified at most once by the evaluation of an expression. Fur-
thermore, the prior value shall be accessed only to determine the
value to be stored. The requirements of this paragraph shall be met
for each allowable ordering of the subexpressions of a full expres-
sion; otherwise the behavior is undefined. [Example:
i =3D v[i++]; // the behavior is undefined
i =3D 7, i++, i++; // 'i' becomes 9
i =3D ++i + 1; // the behavior is undefined
i =3D i + 1; // the value of 'i' is incremented
--end example]
Pierre D=E9nomm=E9e
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]