Eric Maino

System.Brain.CoreDump();

i = i++;

Should the following code, i = i++;, be caught by the compiler as an invalid operation?

I don't know why I thought of writing this code today, but after doing so and testing it in Managed C++, C# and J# (this code was not tested in VB.NET becuase it does not supporte the postfix increment operation), I wonder if this code should just be caught by the compiler.

When the example code is used in a loop, for (int i=0; i<10; i=i++), C++ is the only one too successfuly complete the loop, while J# and C# enter into infinite loops. The reason C# and J# enter into these loops is becuase they call dup, before the increment operation and the original value 0, in code is always the last value to be popped off the stack before the greater than or equal to check is made. This is obviously because the same variable is used rather then x = i++;

Anyhow... What do you think? Should this be caught?

Comments

Geoff Appleby said:

Check this post: http://blogs.msdn.com/lucabol/archive/2004/08/31/223580.aspx where he goes into a pretty good discussion on it :)
# October 24, 2004 9:24 PM

Eric Maino said:

Thanks for the link. It was a good read
# October 24, 2004 10:51 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)