This is from The GNU C Library Reference Manual
int SIGFPE
The SIGFPE signal reports a fatal arithmetic error. This signal actually covers all arithmetic errors, including division by zero and overflow.
BSD systems provide the SIGFPE handler with an extra argument that distinguishes various causes of the exception. In order to access this argument, you must define the handler to accept two arguments, which means you must cast it to a one-argument function type in order to establish the handler.
But there is no example on how to access the extra argument.
I did my google work but could not find anything.
How can I get this extra information?
As EOF mentioned in the comments, the much better way to do this, that doesn't require formally broken casts, and a bonus is correctly documented, is to install your signal handler using sigaction and the SA_SIGINFO flag, and then in the si_code field of the second parameter (type siginfo_t) you can determine which floating-point error occurred:
The following values can be placed in
si_codefor aSIGFPEsignal:
FPE_INTDIVInteger divide by zero.
FPE_INTOVFInteger overflow.
FPE_FLTDIVFloating-point divide by zero.
FPE_FLTOVFFloating-point overflow.
FPE_FLTUNDFloating-point underflow.
FPE_FLTRESFloating-point inexact result.
FPE_FLTINVFloating-point invalid operation.
FPE_FLTSUBSubscript out of range.
Source: Linux sigaction(2) man page
The same list is also readily available on the FreeBSD siginfo man page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With