473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Boxing confuses MS VS 2003 also

Hi
I am sure that this is a bug in MS VS 2003;
Consider the following code:
----
public static void Main() {
int i=1;
int j=1;

object a=1;
object b=1;

object c=i;
object d=j;

object e=i;
object f=i;

object g=b;
object h=b;

if (a==b) {
Console.WriteLine("a==b True");
} else {
Console.WriteLine("a==b False");
}
if (c==d) {
Console.WriteLine("c==d True");
} else {
Console.WriteLine("c==d False");
}
if (i==j) {
Console.WriteLine("i==j True");
} else {
Console.WriteLine("i==j False");
}
if (e==f) {
Console.WriteLine("e==f True");
} else {
Console.WriteLine("e==f False");
}
if (g==h) {
Console.WriteLine("g==h True");
} else {
Console.WriteLine("g==h False");
}
}
----
Add watches for the following expressions
a==b
c==d
e==f
g==h
and run the code in Debug mode.

You will see that the watch window shows the values of these expressions as
'True' (also 'True' in the QuickWatch Window) but the debugging always falls
through the 'else' part in the comparison. Heh...? What is this?

Is this a bug...?

I agian say that MS has wrongly implemented the comparison for boxed
variables.

-
Aamir
Nov 17 '05 #1
2 992
> You will see that the watch window shows the values of these expressions
as
'True' (also 'True' in the QuickWatch Window) but the debugging always
falls
through the 'else' part in the comparison. Heh...? What is this?


You are right, the VS2003 debugger appearantly does a different == than
you would expect.

The VS2005B2 debugger shows it correctly:

a==b --> False, boxing int gives different object each time
c==d --> False, boxing int gives different object each time
e==f --> False, boxing int gives different object each time
g==h --> True, both objects contain reference to B.

Greetings,
Wessel
Nov 17 '05 #2
As Wessel points out, the debugger watch window has this bug, but the code
is executing correctly. The debugger has been fixed in Whidbey.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Aamir Mahmood" <a@b.c> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi
I am sure that this is a bug in MS VS 2003;
Consider the following code:
----
public static void Main() {
int i=1;
int j=1;

object a=1;
object b=1;

object c=i;
object d=j;

object e=i;
object f=i;

object g=b;
object h=b;

if (a==b) {
Console.WriteLine("a==b True");
} else {
Console.WriteLine("a==b False");
}
if (c==d) {
Console.WriteLine("c==d True");
} else {
Console.WriteLine("c==d False");
}
if (i==j) {
Console.WriteLine("i==j True");
} else {
Console.WriteLine("i==j False");
}
if (e==f) {
Console.WriteLine("e==f True");
} else {
Console.WriteLine("e==f False");
}
if (g==h) {
Console.WriteLine("g==h True");
} else {
Console.WriteLine("g==h False");
}
}
----
Add watches for the following expressions
a==b
c==d
e==f
g==h
and run the code in Debug mode.

You will see that the watch window shows the values of these expressions
as 'True' (also 'True' in the QuickWatch Window) but the debugging always
falls through the 'else' part in the comparison. Heh...? What is this?

Is this a bug...?

I agian say that MS has wrongly implemented the comparison for boxed
variables.

-
Aamir

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Lora Connors | last post by:
What is Boxing & UnBoxing in .NET?
4
by: Peter Olcott | last post by:
I want to be able to make my .NET applications run just as fast as unmanaged C++. From my currently somewhat limited understanding of the .NET framework and the C# language, it seems that...
161
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.