delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/27/10:44:56

From: Jeffrey_Krupp AT May-Co DOT com
Subject: Division by zero : SIGFPE
To: djgpp AT delorie DOT com
Date: Fri, 27 Oct 2000 10:43:34 -0400
Message-ID: <OFB44903C9.92C2A467-ON85256985.004F4061@COM>
X-MIMETrack: Serialize by Router on MD110052/SERVERS/MAYCO(Release 5.0.5 |September 22, 2000) at
10/27/2000 09:43:38 AM
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019