Categories:
.NET (357)
C (330)
C++ (184)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (2)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I ensure that integer arithmetic doesnt overflow?
How can I ensure that integer arithmetic doesnt overflow?
✍: Guest
The usual approach is to test the operands against the limits in the header file <limits.h> before doing the operation. For example, here is a ``careful'' addition function:
int
chkadd(int a, int b)
{
if(INT_MAX - b < a) {
fputs("int overflow\n", stderr);
return INT_MAX;
}
return a + b;
}
2015-03-04, 1694👍, 0💬
Popular Posts:
What Is a CAPTION Tag/Element? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells A "capti...
What is the quickest sorting method to use? The answer depends on what you mean by quickest. For mos...
What is shadowing ? When two elements in a program have same name, one of them can hide and shadow t...
How Large Can a Single Cookie Be? - PHP Script Tips - Understanding and Managing Cookies How large c...
How To Download and install PSP Evaluation? - PSP Tutorials - Fading Images to Background Colors wit...