Solved

Learning C# - OverFlowChecker?

Posted on 2007-03-25
2
184 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
2 Comments
 
LVL 15

Accepted Solution

by:
stanscott2 earned 500 total points
Comment Utility
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
Comment Utility
Dude...Excellent Answer!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now