Does anyone know how to check for overflow in a c program?
like when:
How do I know if an overflow has occured?Code:result=var1+var2;
This is a discussion on Checking overflow? within the C++ Programming forums, part of the General Programming Boards category; Does anyone know how to check for overflow in a c program? like when: Code: result=var1+var2; How do I know ...
Does anyone know how to check for overflow in a c program?
like when:
How do I know if an overflow has occured?Code:result=var1+var2;
>How do I know if an overflow has occured?
You cannot do so portably. If overflow is likely then using a larger data type would be a safe alternative. You can also test each value before the operation to determine if overflow is possible.
-Prelude
My best code is written with the delete key.