Floating Point Exception Core Dump

倖福魔咒の 提交于 2019-12-01 16:17:16

Any SIGFPE caused by a hardware trap while the signal is blocked causes undefined behavior:

If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated while they are blocked, the result is undefined, unless the signal was generated by the kill() function, the sigqueue() function, or the raise() function.

(from sigprocmask specification)

man signal

According to POSIX, the behavior of a process is undefined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated by kill(2) or raise(3). Integer division by zero has undefined result.

On some architectures it will generate a SIGFPE signal. (Also dividing the most negative integer by -1 may generate SIGFPE). Ignoring this signal might lead to an endless loop.

I discovered this after trying to work out why negative/positive infinity resulted from a division by zero: IEEE 754, division by zero

This is a place you never want to get:

void divZeroHdlr(int sig) {
  printf("div by zero: %d\n",sig)
  exit(1);}

int main(int argc, char *argv[]) {
  signal(SIGFPE, divZeroHdlr)
  int n = 1/0}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!