C ++ and GCC: how does GCC C ++ manage division by zero?

Just out of interest. How does the GCC C ++ implementation handle standard types of numbers divisible by zero? It's also interesting to know how another compiler works with respect to zero division. Feel free to go into the details. This is not just entertainment, as it is partly related to the purpose of uni.

Cheers, Chaz

+3
source share
1 answer

This is not true. What usually happens is that the CPU will throw an internal exception of some kind when the division instruction has 0 for the operand, which calls the interrupt handler, which reads the state of the various registers on the processor and processes it, usually by converting it to a signal that is sent back to the program and processed by any registered signal handlers. For most UNIX-like operating systems, they get SIGFPE.

While the behavior may change (for example, on some processors you can say that the CPU does not throw an exception, as a rule, they just put some kind of clamped value as 0 or MAXINT), this change is usually due to differences in the OS, CPUm and the runtime, not the compiler.

+9
source

Source: https://habr.com/ru/post/1718886/


All Articles