-
Division by zero
Is that true that VC++ 6.0 compilator doesn't mind if I divide something by zero, or I've missed something? The following code works:
double a;
double b;
a = 10;
b = 0;
try
{
a = a / b;
}
catch (...)
{
// some code.
}
Division by zero wasn't even catched.
-
Re: Division by zero
In is not the job of the compiler to detect such things.
-
Re: Division by zero
According to the C++ Standard (5.5), if the result is not mathematically defined, or not in the range of representable values, the result is undefined (so the compiler can do anything). In the case of divide by zero and floating point exceptions, treatment of the result varies among machines, and may be adjustable via a library routine.
With floating-point arithmetic with VC++ on Intel PCs, division by zero gives a result value in 'a' of infinity, which is represented as 1.#INF. Integer types (e.g. int) will cause an exception to be thrown.
Dave
-
Re: Division by zero
You're right, of course, but I think he really meant the VC++ run-time code...
Whatever :-)
Dave