Can I ignore a SIGFPE resulting from division by zero?
- by Mikeage
I have a program which deliberately performs a divide by zero (and stores the result in a volatile variable) in order to halt in certain circumstances. However, I'd like to be able to disable this halting, without changing the macro that performs the division by zero.
Is there any way to ignore it?
I've tried using
#include <signal.h>
...
int main(void) {
signal(SIGFPE, SIG_IGN);
...
}
but it still dies with the message "Floating point exception (core dumped)".
I don't actually use the value, so I don't really care what's assigned to the variable; 0, random, undefined...
EDIT: I know this is not the most portable, but it's intended for an embedded device which runs on many different OSes. The default halt action is to divide by zero; other platforms require different tricks to force a watchdog induced reboot (such as an infinite loop with interrupts disabled). For a PC (linux) test environment, I wanted to disable the halt on division by zero without relying on things like assert.