Possible Duplicate:
Best way to detect integer overflow in C/C++
Oftentimes when I’ve coded something in C++ using large numbers I can’t tell when overflow is occurring, even if I am using something like a long long or other 64-bit data type. Is there an effective way to detect when overflow is occurring than witnessing erroneous values?
There may not be much that you would get from standard C++:
Your best bet is to probably use the standard fixed width integer types defined in
<cstdint>such asuint32_t.Take a look at the
<cerrno>header too for error codes such asEOVERFLOW. There are then theoverflow_error/underflow_errorclasses from<stdexcept>.