In article <4374d35c$0$21945$>,
Heinz Ozwirk <> wrote:
>"ljh131" <> schrieb im Newsbeitrag
>news: roups.com...
>>i found something wrong code.
>>
>> int i = 0;
>> i = i++;
>>
>> is it standard c++? peoples say i == 1 in most compilers but anothers
>> not the same. if so, may be it's not standard code, however i want know
>> positively.
>
>Yes, it is standard C++, but the behaviour is not defined by the standard.
>In the statement 'i = i++', there is no sequence point and i is modified
>more than once. Many compilers might create code such that finaly i == 1,
>but it is easy to imagine a sequence of code, that results in i == 0:
>
> 1. Evaluate the expression i
> 2. Increment i
> 3. Assign the result of step 1 to i
>
>So remember what they tell the kids in TV -- "Don't do that at work"
Right, the problem is whether the ++ side-effect takes place
before or after the assignment. But we don't get only those
two choices (which is bad enough) and hence as you say it is
undefined behavior.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==>
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?