Solved

Learning C# - OverFlowChecker?

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send parameters via datatable ajax call 4 43
Put File 6 36
C# LINQ query question 11 32
Trying to check to see if email is in valid format in asp.net 3 22
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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