To check for over/underflow in arithmetic check the result compared to the original values.
uint32 a,b;
//assign values
uint32 result = a + b;
if (result < a) {
//Overflow
}
For your specific the check would be:
if (a > (c-b)) {
//Underflow
}
More Related Contents:
- How to handle arbitrarily large integers
- How do I detect unsigned integer overflow?
- Why is unsigned integer overflow defined behavior but signed integer overflow isn’t?
- Is signed integer overflow still undefined behavior in C++?
- Detecting signed overflow in C/C++
- Type of integer literals not int by default?
- How do promotion rules work when the signedness on either side of a binary operator differ? [duplicate]
- (-2147483648> 0) returns true in C++?
- Question about C behaviour for unsigned integer underflow
- Why does long long n = 2000*2000*2000*2000; overflow?
- Efficient unsigned-to-signed cast avoiding implementation-defined behavior
- Addition of two chars produces int
- Overflowing of Unsigned Int
- C++ integer overflow
- Allowing signed integer overflows in C/C++
- Program behaving strangely on online IDEs
- Modular Exponentiation for high numbers in C++
- How disastrous is integer overflow in C++?
- If a 32-bit integer overflows, can we use a 40-bit structure instead of a 64-bit long one?
- Is there some meaningful statistical data to justify keeping signed integer arithmetic overflow undefined?
- Why it is different between -2147483648 and (int)-2147483648
- What is the difference between std::quick_exit and std::abort and why was std::quick_exit needed?
- Compile-time constant id
- Can nullptr be emulated in gcc?
- Does GCC inline C++ functions without the ‘inline’ keyword?
- stl container with std::unique_ptr’s vs boost::ptr_container
- Specialized template function with deleted “general” case fails to compile with g++
- IN/OUT Parameters and how to work with them in C++
- Template function inside template class
- How to cheaply assign C-style array to std::vector?