gpt4 book ai didi

c - 如何获得有关 SIGFPE 信号的更多信息?

转载 作者:行者123 更新时间:2023-12-04 00:25:55 29 4
gpt4 key购买 nike

这来自 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.

但是没有关于如何访问额外参数的例子。

我用谷歌搜索但找不到任何东西。

我怎样才能得到这些额外的信息?

最佳答案

正如 EOF 在评论中提到的,更好的方法是使用 sigactionSA_SIGINFO 标志,然后在第二个参数(类型 siginfo_t)的 si_code 字段中,您可以确定发生了哪个浮点错误:

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

FPE_INTDIV Integer divide by zero.

FPE_INTOVF Integer overflow.

FPE_FLTDIV Floating-point divide by zero.

FPE_FLTOVF Floating-point overflow.

FPE_FLTUND Floating-point underflow.

FPE_FLTRES Floating-point inexact result.

FPE_FLTINV Floating-point invalid operation.

FPE_FLTSUB Subscript out of range.

来源:Linux sigaction(2) man page

同样的列表也可以在 FreeBSD siginfo man page 上轻松获得。 .

关于c - 如何获得有关 SIGFPE 信号的更多信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30628167/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com