Mail Archives: djgpp/2000/10/27/10:44:56
Hi. I have been fighting a division by zero problem. I have seen a few mail
archives dealing with this issue, but even in using examples, I get an
unrecoverable exception. My goal is to ignore the division by zero and
continue on reguardless of the resulting values.
Here is the example that I used:
void handler(int sig)
{
_clear87();
_fpreset();
printf("\nSignal!");
fflush(stdout);
getch();
}
void main(void)
{
int i;
signal(SIGFPE,handler);
i=1/0;
printf("\nAfter division...still alive!");
fflush(stdout);
}
This always enters the handler, but then kicks me out showing the
registers.
Then I tried inserting the following lines before the signal() assignment,
defining a matherr(), and using the -lm (link with math lib):
_fdlib_version = _SVID_;
_control87(EM_UNDERFLOW,~EM_UNDERFLOW);
_control87(EM_INEXACT,~EM_INEXACT);
int matherr(struct exception *e)
{
printf("\nIn matherr!");
fflush(stdout);
getch();
}
But it doesn't call matherr(). Is the call to matherr() supposed to be
automatic when the signal occurs?
Am I making this harder than it is?
Thanks!
- Raw text -