Sub Main() Dim i As Integer i = 0 i = i + 1 End SubWhen I build the above, I get this warning: "opcode 'add.ovf' -- overflow will not throw exception" for the increment line
Really?
  | ||||||||||||||
Why does simple increment throw an overflow warning?
Started by Dan T, Aug 14 2011 12:52 PM
11 replies to this topic
#1Posted 14 August 2011 - 12:52 PM Sub Main() Dim i As Integer i = 0 i = i + 1 End SubWhen I build the above, I get this warning: "opcode 'add.ovf' -- overflow will not throw exception" for the increment line Really? #2Posted 14 August 2011 - 01:02 PM
A quick search reveals we're down in the mud:
From http://www.artima.co...tv/choices.html
#3Posted 06 September 2011 - 02:54 PM
These errors are driving me insane!
But I can't see why VB.net (which also is a CLR language) should give these message while C# does not. #4Posted 06 September 2011 - 03:42 PM If I remember it correctly, VB.NET uses checked operations, because VB6 does too, while C# does not, because it is similar to C/C++, where arithmetic operations do not check for an overflow [citation needed]. #5Posted 06 September 2011 - 06:56 PM Perhaps, but this only happens with the .NET Micro Framework. It's not a problem with the .NET Framework or .NET Compact Framework. #6Posted 06 September 2011 - 08:00 PM
These are ghostly errors. They come and go for me. I found that doing a rebuild all and a regular (incremental?) build had different behavior. At one point, every other build was succeeding, with errors in-between, BUT NO CODE CHANGES! (4.2 RC1, updated SAM-BA, VS VB 2010 Express, Win 7 32-bit)
#7Posted 07 September 2011 - 06:16 AM
Seems like a bug in the VB.net implementation in NETMF to me. Keep in mind that the new firmware compatible with RC2 is due this week so hopefully we'll see fewer errors when using RC2.
Chris, are you reading this?
#8Posted 10 September 2011 - 03:05 AM I think it happens in C#, too. Or nearly the same thing. Build this trivial C# "App": namespace NetduinoPlusApplication1 { public class Program { public static void Main() { // write your code here long i = 3; byte[] myArray = {1,2,3,4,5}; myArray[i] = 255; } } }And you should get the following pair of identical warnings EVERY OTHER build (without code changes). Try it. Hit Build. Build. Build. Build. If you're setup and mine are the same, two of those builds will succeed and two will show these errors: Warning 1 opcode 'conv.ovf.i' -- overflow will not throw exception C:\Users\Dan\AppData\Local\Temporary Projects\NetduinoPlusApplication1\Program.cs 11 13 NetduinoPlusApplication1 Warning 2 opcode 'conv.ovf.i' -- overflow will not throw exception C:\Users\Dan\AppData\Local\Temporary Projects\NetduinoPlusApplication1\Program.cs 11 13 NetduinoPlusApplication1If you "ReBuild", or make code changes and build, you will get the warning every time. The warning is occuring on the 'i' (type long) as array index. If I explicitly cast the index it to short, like this: myArray[(short)i] = 255;then there is no warning. Whether the warning is correct or not is irrelevant. It's ghostly toggle behavior is NOT correct - the code isn't toggling. Forum people, Please build the above 4 times in a row without code changes and count how many times you get warnings. Please post your results. "Zero" is what you'd expect. "Four" might be reasonable. "Two" is just plain weird. Also post your stats. Here are my results: "Two" (4.2 RC1, updated SAM-BA, VS C# 2010 Express, Win 7 32-bit) #9Posted 11 September 2011 - 12:31 PM
C#:
I built it first time. Got two errors. Rebuilt: No errors But what happens when you change Long to Int? VB.net Built the code multiple times. No errors at all. Public Shared Sub Main() ' write your code here Dim i As Integer = 3 Dim myArray As Byte() = {1, 2, 3, 4, 5} myArray(i) = 255 End Sub However, i tried this: Public Shared Sub Main() Dim k As Integer = 3 Dim l As Integer = 4 Dim m As Integer = k + l End Sub When I build it I get one error. When I build it again I get no errors. If I build it a third time, I get one error again. And that way it goes. If I try the same thing in C# I get NO errors regardless of how many times I build it. public static void Main() { int k = 3; int l = 4; int m = k + l; } #10Posted 11 September 2011 - 06:30 PM
Very interesting. Can you please post this as a bug report at netmf.codeplex.com (and then those affected can vote on it)? It appears to be a bug in the .NET MF 4.2 beta SDK or compiler.
Chris
#11Posted 11 September 2011 - 09:20 PM
Done. Moskus and anyone else seeing this warning, vote for this issue on CodePlex: Overflow warning occurs only on successive builds (weird) #12Posted 13 September 2011 - 06:28 AM
Done!
0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||