Re: Sequence point problem?
From: Jack Klein (jackklein_at_spamcop.net)
Date: 02/06/05
- Next message: Alex Vinokur: "Re: sizeof"
- Previous message: Jack Klein: "Re: sizeof"
- In reply to: Victor Bazarov: "Re: Sequence point problem?"
- Next in thread: Victor Bazarov: "Re: Sequence point problem?"
- Reply: Victor Bazarov: "Re: Sequence point problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 06 Feb 2005 03:43:52 -0600
On Sat, 5 Feb 2005 15:31:49 -0500, "Victor Bazarov"
<v.Abazarov@comAcast.net> wrote in comp.lang.c++:
> "Dave" <better_cs_now@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.
There is a sequence point in this expression, at the '?' after the
condition has been evaluated but before the evaluation of the chosen
predicate expression.
But your reasoning and correction are right.
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
- Next message: Alex Vinokur: "Re: sizeof"
- Previous message: Jack Klein: "Re: sizeof"
- In reply to: Victor Bazarov: "Re: Sequence point problem?"
- Next in thread: Victor Bazarov: "Re: Sequence point problem?"
- Reply: Victor Bazarov: "Re: Sequence point problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|