|Non-Confidential||PDF version||ARM DUI0472J|
|Home > Compiler Coding Practices > About trapping integer division-by-zero errors with __aeabi_idiv0()|
You can trap integer division-by-zero errors with the C library helper function
__aeabi_idiv0() so that division by zero returns some standard result, for example zero.
Integer division is implemented in code through the C library helper functions
__aeabi_uidiv(). Both functions check
for division by zero.
When integer division by zero is detected, a branch to
made. To trap the division by zero, therefore, you only have to place a breakpoint on
The library provides two implementations of
__aeabi_idiv0(). The default
one does nothing, so if division by zero is detected, the division function returns zero.
However, if you use signal handling, an alternative implementation is selected that calls
If you provide your own version of
__aeabi_idiv0(), then the division
functions call this function. The function prototype for
__aeabi_idiv0() returns a value, that value is used as the quotient
returned by the division function.