J
Jason
This is an offshoot of my post "c# XOR equals (^=) bug?".
While I was working on the code for that problem, I think
I found a problem with the VS.NET debugger. That has to
do with the quick evaluation tooltips while debugging.
Here is the basic code to use for debugging and to
illustrate this "problem.":
//--- start code
using System;
class Class1
{
[STAThread]
static void Main(string[] args)
{
int x = 1;
int y = 2;
Console.WriteLine("before swap");
Console.WriteLine("x: {0}", x);
Console.WriteLine("y: {0}", y);
Swap(ref x, ref y);
Console.WriteLine("\nafter swap");
Console.WriteLine("x: {0}", x);
Console.WriteLine("y: {0}", y);
}
public static void Swap(ref int x, ref int y)
{
x ^= y;
y ^= x;
x ^= y;
}
} //end code
When debugging, highlighting an expression like "x ^= y"
with the mouse
and then hovering over the operator will display a
tooltip with the answer. However the original values
change and from that point on the values may not be
correct!
To reproduce in the code from above:
1. Load the above code into VS.NET. I used 2003.
2. Put a breakpoint on the first of the three lines of
the triple XOR swap.
public static void Swap( ref int x, ref int y)
{
BP--> x ^= y;
y ^= x;
x ^= y;
}
3. run the code in debug mode. the program will stop on
the breakpoint.
4. now, without advancing (no F10), highlight the one of
the expressions with the mouse and then hover over the
operator (^=) in that line. The tooltip will show the
results of the evaluation, but now the values in x and y
are changed permanently.
NOTE: when highlighting, make sure not to highlight the
semicolon at the end of the line or the tooltip won't
show.
Jason P.
..
While I was working on the code for that problem, I think
I found a problem with the VS.NET debugger. That has to
do with the quick evaluation tooltips while debugging.
Here is the basic code to use for debugging and to
illustrate this "problem.":
//--- start code
using System;
class Class1
{
[STAThread]
static void Main(string[] args)
{
int x = 1;
int y = 2;
Console.WriteLine("before swap");
Console.WriteLine("x: {0}", x);
Console.WriteLine("y: {0}", y);
Swap(ref x, ref y);
Console.WriteLine("\nafter swap");
Console.WriteLine("x: {0}", x);
Console.WriteLine("y: {0}", y);
}
public static void Swap(ref int x, ref int y)
{
x ^= y;
y ^= x;
x ^= y;
}
} //end code
When debugging, highlighting an expression like "x ^= y"
with the mouse
and then hovering over the operator will display a
tooltip with the answer. However the original values
change and from that point on the values may not be
correct!
To reproduce in the code from above:
1. Load the above code into VS.NET. I used 2003.
2. Put a breakpoint on the first of the three lines of
the triple XOR swap.
public static void Swap( ref int x, ref int y)
{
BP--> x ^= y;
y ^= x;
x ^= y;
}
3. run the code in debug mode. the program will stop on
the breakpoint.
4. now, without advancing (no F10), highlight the one of
the expressions with the mouse and then hover over the
operator (^=) in that line. The tooltip will show the
results of the evaluation, but now the values in x and y
are changed permanently.
NOTE: when highlighting, make sure not to highlight the
semicolon at the end of the line or the tooltip won't
show.
Jason P.
..