Re: Sequence point problem?
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 02/05/05
- Next message: Victor Bazarov: "Re: FAQ issue: Guaranteed value ranges of fundamental types?"
- Previous message: infobahn: "Re: FAQ issue: Guaranteed value ranges of fundamental types?"
- In reply to: Dave: "Sequence point problem?"
- Next in thread: Jack Klein: "Re: Sequence point problem?"
- Reply: Jack Klein: "Re: Sequence point problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 5 Feb 2005 15:31:49 -0500
"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.
V
- Next message: Victor Bazarov: "Re: FAQ issue: Guaranteed value ranges of fundamental types?"
- Previous message: infobahn: "Re: FAQ issue: Guaranteed value ranges of fundamental types?"
- In reply to: Dave: "Sequence point problem?"
- Next in thread: Jack Klein: "Re: Sequence point problem?"
- Reply: Jack Klein: "Re: Sequence point problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|