Solved

Learning C# - OverFlowChecker?

Posted on 2007-03-25
2
186 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

805 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