Thursday, February 20, 2014

Demonstrable bug in C#

Meanwhile, this gives me a compiler error on the first instance of y in the calculation: Use of unassigned local variable 'y' -- definitely a compiler problem here, I'd say: by definition, y should be assigned by the time that part of the expression is evaluated:



int i = 381;
int j = 529;
int x, y;
i = (y ^ (x = (j ^ (y = i ^ j)))); j = x;
Console.WriteLine("i=" + i.ToString() + "; j=" + j.ToString());

My guess is that any instance of the variables in a single line of calculation is thought of as being what the value of the variable was at the start of the computation -- no allowance has been made for the variables to mutate as the calculation progresses. This is actually a serious bug, if you think about it.




No comments:

Post a Comment