Amazon.com Widgets

About Int32's DontTouchThis()

On a recent post, someone asked about the Int32.DontTouchThis() method..  I thought more folks would want to hear it...

From int32.cs
#if _DEBUG
private void DontTouchThis() {
m_value = 0;
}
#endif

Our C# compiler has some great logic for detecting unused fields. Unfortunately the compiler didn’t special case the base class library. We got compiler warnings when compiling Int32 and some other classes saying their internal m_value field either wasn’t used, or always had its default value of 0. The compiler warning here is an error (the field was there for suitable, base level reasons). Instead of disabling those warnings globally for mscorlib (which would have hidden problems in other classes) we ended up adding in these DontTouchThis methods to convince the compiler that we’re doing something with that field, to simply silence the compiler warning.

Now we do have the relatively new #pragma support in the C# compiler, so we can disable these warnings on a finer grained level. However, we left many of the classes with the DontTouchThis method as-is, simply because of time. Since we don’t include the DontTouchThis methods in retail builds, we get almost no gain from doing this.

Brian Grunkemeyer
MS CLR Base Class Library team

Published 31 January 05 09:54 by BradA
Filed under:

Comments

# G. Man said on February 1, 2005 7:31 AM:
So nobody cared when you got the compiler warning in release mode? (!!?)
# Jeff Atwood said on February 2, 2005 6:24 PM:
You should have called it

CantTouchThis() { }

OH OH! OH! OH OH OH! HAMMA TIME!
# JASoft.org said on February 3, 2005 2:54 AM:
Curiosidad sobre el c
New Comments to this post are disabled

Search

Go

This Blog

Syndication

Page view tracker