Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Learning C# - OverFlowChecker?

Posted on 2007-03-25
2
Medium Priority
?
203 Views
Last Modified: 2013-12-17
Im reading Beginning Visual C# and in a section on Type Conversions we are introduced to "Overflow Checking". Pretty cool, but the author goes on to illustrate how Overflow Checking can be configured at the project level. This book - I later found out - is a bit old and references an older version than i'm using (Visual Studio 2K5).  

Now for the questions...
1. Overflow Checking seems to be a good idea, so should it ALWAYS be used ...by default?
2. If not, why not?
3. If so, how (in Visual Studio 2k5) can this be set up (again my book navigates through options I dont seem to have)

thanks,
sleeper
0
Comment
Question by:the_sleeper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
stanscott2 earned 2000 total points
ID: 18788937
1)  NO
2)  There's a performance penalty, so it should only be turned on during Debug/testing
     There are some algorithms that need to ignore overflows, not trap them.  An example would be a checksum, as well as some random and encryption algorithm.  In other words, these rely on arithemetic being done in modulus 2 ^ 32, where the high bits are just ignored.

You should also be aware that it's only done on integer arithmetic; it doesn't work for floats, decimals, etc.  Also, a lot of people don't know that division by zero does NOT produce an overflow error; this always throws a DivideByZeroException.

Also, you can always use the "checked" and "unchecked" keywords where you definitely want to trap or ignore this.   You'll have much more control this way.

For VS 2005, you select the global option this way:

With a project selected in Solution Explorer, on the Project menu.
click Properties.

Click the Compile tab.

Click the Advanced Compile Options button.

In the Advanced Compiler Settings dialog box, there is a Remove integer
overflow checks check box.
0
 

Author Comment

by:the_sleeper
ID: 18789032
Dude...Excellent Answer!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question