"Dave" <be***********@yahoo.com> wrote...
Can anybody identify any sequence point problems in the expression below?
i = (i == string::npos) ? 0 : ++i;
The Standard says that between sequence points (and there are none in
this expression) a stored value of any object shall be modified at most
once. If the expression in the parentheses yields false, 'i' will be
modified twice, once by ++ and the other time with the assignment, which
causes undefined behaviour. If you rewrite this as
i = (i == string::npos) ? 0 : i + 1;
there would be no problem.
V