How to turn off Overflow Checks?!?

Is there any good reason for not having the ability to turn off overflow checks in VB.NET Express I know that this is an "advanced" option, but lots of common code code doing some binary operations will break and not be usable for beginners to run and study. That's pretty bad IMHO. There's the workaround of course by putting the "RemoveIntegerChecks" XML element in the vsproj file manually, but why all this pain, Microsoft, why Thanks for listening!



Answer this question

How to turn off Overflow Checks?!?

  • ardmore

    How do I teach (which I don't btw) that for instance

    Dim offset as UShort
    Dim data as Integer() = New Integer(63999) {}

    offset = 30000
    data(
    offset) = 1
    offset += 42000
    data(ofs) = 2

    is in many areas of informatics a valid operation, since the overflow is as expected, like addressing in a circular buffer. I must admit that this is something more advanced of course - and if rockets plunge into the ocean because of that it might be good not too tell it at all.

    Happy overflowing!





  • nick-ow-lo-d-eon

    You're right that total beginners won't suffer. However VBE was also advertised as being ideal for hobbyists, who might want to do a little bit more, for which VBE is really great and hardly misses anything. And yes, OV checks are fixable by hand, but even freebie Delphi once came with such a check box, since it's just part of the language. And MS didn't deactivate the __unchecked keyword in VCS Express, or did they


  • Christer O

    If you're teaching, it's difficult for me to see the virtue of code that has overflows to begin with.



  • JamesDawson

    What kind of code wouldn't run I can't imagine any kind of beginner appropriate code which wouldn't run under such circumtances.

    Even so, if you supplied such code to a user - which you say wouldn't run because of the integer checks - even with the professional edition you would have to inform your users to disable it. If this is just an example for the students, editing the XML is not a big deal, anyway.



  • pyphehe

    I understand. My major issue is that I cannot pass some sample code to a beginner/student since it won't run. IMHO you should at least be able to run the basic language (no pun indented ).

  • Tom Bowen

    Yes, I'm also a little bit annoyed that in C#

    int x = 0xffffffff;

    is not legal, but you have to write it like this:

    int x = __unchecked((int)0xffffffff);

    Overflow checks are good, don't get me wrong. Yet be aware that code performance suffers a little bit, too.



  • cb3431

    Interesting.

    When writing for rocketry, I hope they aren't using VB! You are right, of course, the there are a few assembly lines of code attached to the overflow checking - but it's not something a VB programmer, I believe, should worry about.

    It comes down to philosopy, really: VB for me, is a program to get things done. Programming is not a job, it's a tool. It doesn't have to be efficient, it has to be effective. I don't want it kicking me when I least expect it. Such things that we are discussing here is one of those things - we've all heard of the dreaded buffer overflow issues - it's a similar problem.

    Indeed, the nature of a lot of my programming often repeats bounds checks on arrays, for example, if the code is called bupassing the initial bounds check, there's an additional one to catch it - true, the end result may be unexpected, but at least it will be observable and rectified relatively quickly. Stability over efficiency is paramount - and really should be for any high level language programmer.

    (Now, if I'm more interested in efficiency, say, for a flux vector drive, calculating the virtual field value on a three phase motor, then clock cycles on an 8mhz processor matters. This is going to be C code with a smattering of hand optimized assembler.)

    Do programmers need to be aware of such things Of course. But it's all about appropriate tools: C programming is ideal to teach and learn about basic data structures, bit representation, overflows, algorithms, etc. If you actually want to get something done (i.e. a usable product) then a higher level, more productive, environment is needed. (obviously, it depends on the market - there is a negligible market elegant and efficient C code, though).



  • tangentier

    I'm very thankful that:

    Dim offset as UShort
    offset = 30000

    causes and overflow.

    However

    const n As Uint64 = &H8000000000000000

    Dim a As Uint64

    a = n

    Will also cause an overflow and I don't think that's correct.



  • Alexander M. Santos

    I understand that for regular programming with numbers using the larger type is the solution. However I'm doing e.g. implementations of cryptographic algorithms, where many often you see definitions like a = (b + x) mod 32, so overflows are expected and basically truncated. In a is an Int32 then of course an Int64 would be the cleanest way, however for performance reasons (and it matters if MBs of data per seconds are going through your system) you want to do it in Int32 without overflows. That's probably the "dark side" of VB programming. For me VB.NET is great and absolutely equal to C# when it comes to performance nowadays, with the right knowledge both will emit equal MSIL code when it comes to speed. As long as a developer doesn't want to leave the managed world this means that she can do everything in her favorite language - there's no reason at all anymore to point to C# or Managed C++ when it comes to speedy implementations.

  • kidd

    Go ahead and purchase the more advanced IDE: Standard or professional if you really need this feature.

    VBExpress is a tool designed for beginners, who may not even know what an integer overflow check is, so presenting all these options wil overwealm the beginner. VB Express is (currently) free with a cut down featureset. Turning off such compiler options is not a beginners feature.



  • Vítor

    The VB compiler will be happier if you tell it that the constant that you are assigning to n is an unsigned long (using the UL suffix).

    Const n As UInt64 = &H8000000000000000UL
    Dim a As UInt64
    a = n

    If I wanted to "allow" overflows, I'd probably be explicit about what I wanted to happen in my code by using the next larger type in my calculation and mask off the bits that I was interested in.

    Dim offset As UShort
    Dim data As Integer() = New Integer(63999) {}
    offset = 30000
    data(offset) = 1
    offset =
    CUShort((42000 + offset) And UShort.MaxValue)
    data(offset) = 2

    Of course, to do this would have been more difficult if I wanted to use a UInt64 in the first place...

    Best regards,
    Johan Stenberg



  • How to turn off Overflow Checks?!?