c - 除以零中断错误 "using float variables"

标签 c interrupt divide-by-zero

使用 C 进行编码(dev c++) 我正在使用:

void h(int x)
{
    printf("error devide by zero");
}

signal(SIGFPE, h);
x = a / 0;
printf("%d", x)
<小时/>

它与 int a, x; 配合得很好 但是当我使用float a, x;时错误消息是:"#INF " 有人告诉我可以用汇编来中断,其他人告诉我必须中断BIOS,但没有给出解决方案

最佳答案

Floating-Point environment定义是否因除零而生成异常。除非您明确打开或关闭它,否则您得到的行为是未定义的。

此外,您还使用 h 函数本身作为信号处理程序。当信号发出时,这会导致无限循环。

关于c - 除以零中断错误 "using float variables",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43569343/

相关文章:

linux - 检索 tasklet 的 pid

operating-system - 中断向量。位置/谁设置的?

interrupt - 为什么这种情况下UART发送中断不起作用?

python - Pandas/numpy 加权平均 ZeroDivisionError

python - 使用 numpy.select 避免 div/0 错误

c++ - 是否有 C/C++ 函数可以安全地处理被零除?

c - 从#define 函数返回一个字符串

多个可执行文件共享的动态库的公共(public)函数

c - vim 中 C 程序的 memcpy 和 malloc 语法高亮显示

c - 如何读取不同长度的子串