Re: Nasty bug in the C# compiler, it truncates values on the stack
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 4 May 2005 20:32:02 +0200
Might I suggest that this gets escalated to the C# guys via our internal
route too..
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
news:%23%23aoKXNUFHA.3952@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Jerry" <jerrygoodman@xxxxxxxxx> wrote in message
> news:q68ee.10$fQ2.2@xxxxxxxxxxx
>>I managed to narrow this down to a very simple expression. try this:
>>
>> private void Bug()
>> {
>> bool b = false;
>> Test(3, (b || b) && b && !b);
>> }
>>
>> private void Works()
>> {
>> bool b = true;
>> Test(3, (b || b) && b && !b);
>> }
>>
>> private void Test(decimal v, bool b)
>> {
>> MessageBox.Show(v.ToString());
>> }
>>
>> The value of the argument v in Test() is 0!
>>
>> If you change the function Bug() and make bool b = true it works fine. I
>> checked the MSIL code and it appears that the compiler chocked on the
>> expression "(b || b) && b && !b" and silently truncated the previous
>> argument to bool (1 byte). Since the argument is a decimal it will show
>> zero
>> because the truncation occurs on the decimal structure.
>>
>> You can try this with any struct and any value as the first argument, the
>> compiler will always truncate the struct on the stack to 1 byte. If you
>> try
>> with your own struct you will lose all the data after the first byte.
>>
>> Strangely enough, if you remove the parenthesis "b || b && b && !b" is
>> works
>> fine.
>>
>> Plese don't focus on the expression, it's a simplification of a real
>> expression. The nastiest part is that there is no compiler error or
>> warning,
>> it simply generates wrong MSIL code.
>>
>> Is this a known bug? If not, how do I report this to Microsoft and to the
>> .NET team?
>>
>> I tried in the past to report a bug with the shortcircuit operators specs
>> and compiler but didn't suceeded and the defect is still there.
>>
>> I also tried with the latest service pack, the version shown in the .NET
>> Configuration module is version 1.1.4322.573.
>>
>>
>
> Yep, looks like a bug.
>
> You can report bugs/issues to
> http://lab.msdn.microsoft.com/productfeedback/default.aspx
>
> Willy.
>
>
.
- Follow-Ups:
- Re: Nasty bug in the C# compiler, it truncates values on the stack
- From: Willy Denoyette [MVP]
- Re: Nasty bug in the C# compiler, it truncates values on the stack
- References:
- Nasty bug in the C# compiler, it truncates values on the stack
- From: Jerry
- Re: Nasty bug in the C# compiler, it truncates values on the stack
- From: Willy Denoyette [MVP]
- Nasty bug in the C# compiler, it truncates values on the stack
- Prev by Date: Re: No method in C# but exists in VB?
- Next by Date: Re: Nasty bug in the C# compiler, it truncates values on the stack
- Previous by thread: Re: Nasty bug in the C# compiler, it truncates values on the stack
- Next by thread: Re: Nasty bug in the C# compiler, it truncates values on the stack
- Index(es):
Relevant Pages
|