如何获取有关 SIGFPE 信号的更多信息? [英] How to get further information on SIGFPE signal?

查看:73
本文介绍了如何获取有关 SIGFPE 信号的更多信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本文来自GNU C 库参考手册

int SIGFPE

SIGFPE 信号报告了一个致命的算术错误.这个信号实际上涵盖了所有算术错误,包括除以零和溢出.

The SIGFPE signal reports a fatal arithmetic error. This signal actually covers all arithmetic errors, including division by zero and overflow.

BSD 系统为 SIGFPE 处理程序提供了一个额外的参数区分异常的各种原因.为了访问这个参数,你必须定义处理程序来接受两个参数,这意味着您必须按顺序将其强制转换为单参数函数类型建立处理程序.

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?

推荐答案

正如 EOF 在评论中提到的那样,更好的方法是做到这一点,不需要正式打破强制转换,并且正确记录了奖金,是使用 sigactionSA_SIGINFO 标志安装您的信号处理程序,然后在第二个参数的 si_code 字段中(键入 siginfo_t) 可以确定发生了哪个浮点错误:

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:

对于 SIGFPE 信号,以下值可以放在 si_code 中:

The following values can be placed in si_code for a SIGFPE signal:

FPE_INTDIV整数除以零.

FPE_INTDIV Integer divide by zero.

FPE_INTOVF整数溢出.

FPE_INTOVF Integer overflow.

FPE_FLTDIV浮点数除以零.

FPE_FLTDIV Floating-point divide by zero.

FPE_FLTOVF浮点溢出.

FPE_FLTOVF Floating-point overflow.

FPE_FLTUND浮点下溢.

FPE_FLTUND Floating-point underflow.

FPE_FLTRES浮点不精确结果.

FPE_FLTRES Floating-point inexact result.

FPE_FLTINV浮点无效运算.

FPE_FLTINV Floating-point invalid operation.

FPE_FLTSUB下标超出范围.

FPE_FLTSUB Subscript out of range.

来源:Linux sigaction(2) 手册页

同样的列表也可以在 FreeBSD siginfo 手册页上找到.

The same list is also readily available on the FreeBSD siginfo man page.

这篇关于如何获取有关 SIGFPE 信号的更多信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆