Re: Postfix increment



>
> "Oleg Kharitonov" <kh_oleg@xxxxxxx> wrote in message
> news:ORAKrlBwFHA.664@xxxxxxxxxxxxxxxxxxxxxxx
>> Hello!
>>
>> I have found an interesting thing with postfix operator ++.
>>
>> What should contain the variable i after exceution the following code:
>>
>> int i = 5;
>> i = i++;
>>
>> In VC++ 7.1 and VC++ 2005 beta 2 the variable i contains 6.
>> But in C# 7.1 and C# 2005 beta 2 the variable i contains 5.
>>
>> Is it behaviour correct? Can anyone explain what is the correct result?
>>
>> Best regards,
>> Oleg.
>
> The correct behavior is for the compiler to wipe out your harddrive and
> call you names, so as to prevent you from writing any code that bad again.
> :^)
>
> In C/C++ the behavior of
> [ i = i++ ; ]
> is undefined.
>
> I have not found anywhere in the C# standard where they discuss sequence
> points yet.
> So it is possible that this behavior is "Defined" in C#.
>
> It should, however, be avoided at all costs
>
> Bill

It's clearly defined in the C# standard. There's no reason to avoid it. If
it is undefined in C++, then it should be avoided in C++.

Pete


.



Relevant Pages

  • Re: C++ Coding Standards
    ... In standard C is not possible to replace ... Avoid magic numbers. ... Always write internal #include guards. ...
    (comp.lang.c)
  • Re: returning address of stack variable
    ... pete said: ... You can grep on "variables" in the standard. ... the value of each variable to int size and then add the two int s and ... between a ``variable pointer to a constant value'' and a ``constant ...
    (comp.lang.c)
  • Re: I want to learn forth but...
    ... A bunch of nested returns for no particular reason except that it ... was too hard to avoid them. ... I think that is used in many Forths at this point. ... standard code isn't supposed to do that. ...
    (comp.lang.forth)
  • Re: Meat Prices Going Up
    ... Pete C. wrote: ... measures have the same standard of living as the US. ... Spicy chicken stir-fry, copied ...
    (rec.food.cooking)
  • Re: Office 2003 Standard and Access 97 on same computer
    ... Everything okay with this scenario? ... Avoid using IE to open docs from. ... office have purchased MVL editions of Office 2003 standard. ...
    (microsoft.public.office.misc)