There may not be much that you would get from standard C++:
5 Expressions
4 If during the evaluation of an expression, the result is not
mathematically defined or not in the range of representable values for
its type, the behavior is undefined. [ Note: most existing
implementations of C++ ignore integer overflows. Treatment of division
by zero, forming a remainder using a zero divisor, and all floating
point exceptions vary among machines, and is usually adjustable by a
library function. —end note ]
Your best bet is to probably use the standard fixed width integer types defined in <cstdint>
such as uint32_t
.
Take a look at the <cerrno>
header too for error codes such as EOVERFLOW
. There are then the overflow_error
/underflow_error
classes from <stdexcept>
.