Re: Funny loop with post-increment.

Ryan Heath <[email protected]> Tue, 19 Feb 2008 09:35:38 +0100
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
For one reason I had always thought C# had abandoned this peculiar C++
feature...

Anyone know why C# has this feature, its obvious that still people are
confused of it.
Wasn't C# about getting things *simpler and easier* than its cousins C/C++ ?

// Ryan

On Feb 19, 2008 9:24 AM, Jon Skeet <[email protected]> wrote:
> Frans Bouma wrote:
> >> In other words, the increment happens after the evaluation of i, but
> >> before the assignment - so the assignment just sets it back to the
> >> original value.
> >
> >         I don't find this obvious. Right-hand side of the assignment should be
> > evaluated first, so:
> > i=i+1
> > i=i
> >
>
> The RHS of the assignment *is* evaluated first - the result of "i++" is
> the value *before* the increment. So, when i = 0 the value of the
> expression "i++" is 0. That value is then assigned to i.
>
>  >         I don't see how /why a temp variable is suddenly created.
>
>  From the spec (7.5.9)
>
> <quote>
> •     If x is classified as a variable:
> o       x is evaluated to produce the variable.
> o       The value of x is saved.
> o       The selected operator is invoked with the saved value of x as its
> argument.
> o       The value returned by the operator is stored in the location given by
> the evaluation of x.
> o       The saved value of x becomes the result of the operation.
> </quote>
>
> Here I'm just using tmp to be "the saved value".
>
>
> Jon
>
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com