Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Why does simple increment throw an overflow warning?


  • Please log in to reply
11 replies to this topic

#1 Dan T

Dan T

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationBoston (Greater)

Posted 14 August 2011 - 12:52 PM

Sub Main()
    Dim i As Integer
    i = 0
    i = i + 1
End Sub
When I build the above, I get this warning: "opcode 'add.ovf' -- overflow will not throw exception" for the increment line

Really?

#2 Dan T

Dan T

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationBoston (Greater)

Posted 14 August 2011 - 01:02 PM

A quick search reveals we're down in the mud:

From http://www.artima.co...tv/choices.html

IL [Intermediate Language] has add to add two numbers, add.ovf to add two numbers and trap signed overflow, and add.ovf.un to add two numbers and trap unsigned overflow. All of these instructions pop two values off the top of the stack, add them, and push the result back.
... By contrast, the CLR's [Common Language Runtime] add instructions are polymorphic, they add the two values on the top of the stack, whatever their type, although the trap overflow versions differentiate between signed and unsigned.



#3 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 06 September 2011 - 02:54 PM

These errors are driving me insane! Posted Image

But I can't see why VB.net (which also is a CLR language) should give these message while C# does not. Posted Image

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 06 September 2011 - 03:42 PM

But I can't see why VB.net (which also is a CLR language) should give these message while C# does not. Posted Image

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].

#5 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 06 September 2011 - 06:56 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].

Perhaps, but this only happens with the .NET Micro Framework. It's not a problem with the .NET Framework or .NET Compact Framework.

#6 Dan T

Dan T

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationBoston (Greater)

Posted 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)

#7 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 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? ;)

#8 Dan T

Dan T

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationBoston (Greater)

Posted 10 September 2011 - 03:05 AM

But I can't see why VB.net (which also is a CLR language) should give these message while C# does not. Posted Image

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	NetduinoPlusApplication1
If 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)



#9 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 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;
        }


#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 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

#11 Dan T

Dan T

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationBoston (Greater)

Posted 11 September 2011 - 09:20 PM

Can you please post this as a bug report at netmf.codeplex.com

Chris


Done.

Moskus and anyone else seeing this warning,
vote for this issue on CodePlex: Overflow warning occurs only on successive builds (weird)

#12 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 13 September 2011 - 06:28 AM

Done! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.