c++ - Can I make sure that no exception happens on overflow integer miltiplication? -
I am writing a code that makes some arithmetic over long values and it can not produce overflow exceptions.
The code needs to be compiled on both Windows (Visual Studio) and Linux (ARM Linux).
Is there a program or compilation of time instructions, which I can use to compile it should not generate an overflow exception for that specific code
The main point is:
1- It works both on Windows and Linux
2- Despite the general configuration of the project, this section should not be overflow exception (hence Setting up a parameter in the project That is not the best solution).
I do not know about any of the implementations which generate an overflow exception for expression with integral types Will do But the question is what do you want to do? I know that all Windows and Linux compilers will give wrong results, and I can not think of a situation where it would be better for any option the beginning of calculations Prior to this, the general way of handling this type of problem is by using pre-condition check. You know the calculations that are being made, so you can determine the range of values that can be controlled safely without overflow, and you confirm the input that in that range before the start is.
Comments
Post a Comment