Compiler question
-
Hello, Today I've noticed something interesting to me and I'd like to understand. Let's say I have a function like this one:
public enum SomeEnum
{
Value1 = 0,
Value2 = 1
}public void DoSomething(SomeEnum theEnum)
{
if(theEnum == SomeEnum.Value1)
return;
}When I build the project which is a ClassLibrary in Debug mode the compiler translates that to:
public void DoSomething(SomeEnum theEnum)
{
if(theEnum == 0)
{
return;
}
}But when I build the same project in Release mode the result is:
public void DoSomething(SomeEnum theEnum)
{
if(theEnum == null)
{
return;
}
}This seems to happen only when the Enum has two values. Anyone? Thanks.
-
Hello, Today I've noticed something interesting to me and I'd like to understand. Let's say I have a function like this one:
public enum SomeEnum
{
Value1 = 0,
Value2 = 1
}public void DoSomething(SomeEnum theEnum)
{
if(theEnum == SomeEnum.Value1)
return;
}When I build the project which is a ClassLibrary in Debug mode the compiler translates that to:
public void DoSomething(SomeEnum theEnum)
{
if(theEnum == 0)
{
return;
}
}But when I build the same project in Release mode the result is:
public void DoSomething(SomeEnum theEnum)
{
if(theEnum == null)
{
return;
}
}This seems to happen only when the Enum has two values. Anyone? Thanks.
_Zorro_ wrote:
the compiler translates that to...
I doubt that very much. How do you make such observation? if reflector is involved (which version?), have a look at the IL code itself (not the decompiled "source" code), and show it here. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hello, Today I've noticed something interesting to me and I'd like to understand. Let's say I have a function like this one:
public enum SomeEnum
{
Value1 = 0,
Value2 = 1
}public void DoSomething(SomeEnum theEnum)
{
if(theEnum == SomeEnum.Value1)
return;
}When I build the project which is a ClassLibrary in Debug mode the compiler translates that to:
public void DoSomething(SomeEnum theEnum)
{
if(theEnum == 0)
{
return;
}
}But when I build the same project in Release mode the result is:
public void DoSomething(SomeEnum theEnum)
{
if(theEnum == null)
{
return;
}
}This seems to happen only when the Enum has two values. Anyone? Thanks.
-
_Zorro_ wrote:
the compiler translates that to...
I doubt that very much. How do you make such observation? if reflector is involved (which version?), have a look at the IL code itself (not the decompiled "source" code), and show it here. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Sorry for the delay, didn't checked my mail in a while :doh: Ok, I had to be drunk that day, even if i'm pretty sure of what I saw I am unable to reproduce that issue today... It's been an hour I'm trying with no success so I'll leave it there. I shouldn't have deleted my test project... :doh: Thank's to you both for your answers and happy new year!
-
Also doubt that, especially since the optimizing compiler is likely to change the test to !theEnum instead of using the == operator.