Thread View: comp.os.msdos.programmer
2 messages
2 total messages
Started by Bernie Roehl
Wed, 01 Aug 1990 12:53
Turbo C matherr() function
Author: Bernie Roehl
Date: Wed, 01 Aug 1990 12:53
Date: Wed, 01 Aug 1990 12:53
23 lines
1159 bytes
1159 bytes
The problem is simple... maybe the solution will be, too.
I'm trying to define my own matherr() function, as described on page 242 of
the Reference Guide.
#include <math.h>
int matherr(struct exception *e)
{
fprintf(stderr, "Hello, world!\n");
return 1;
}
I then write a short program that just divides by zero, link it with the above,
and run it. Instead of "Hello, world!\n", I get the standard Turboc C
"Floating point error: Divide by 0".
Any ideas/suggestions/etc will be much appreciated. Thanks in advance...
--
Bernie Roehl, University of Waterloo Electrical Engineering Dept
Mail: broehl@watserv1.waterloo.edu OR broehl@watserv1.UWaterloo.ca
BangPath: {allegra,decvax,utzoo,clyde}!watmath!watserv1!broehl
Voice: (519) 885-1211 x 2607 [work]
Re: Turbo C matherr() function
Author: Pete Holzmann
Date: Fri, 03 Aug 1990 13:13
Date: Fri, 03 Aug 1990 13:13
28 lines
1746 bytes
1746 bytes
broehl@watserv1.waterloo.edu (Bernie Roehl) writes:
>The problem is simple... maybe the solution will be, too.
>I'm trying to define my own matherr() function, as described on page 242 of
>the Reference Guide.
>
>I then write a short program that just divides by zero, link it with the above,
>and run it. Instead of "Hello, world!\n", I get the standard Turboc C
>"Floating point error: Divide by 0".
>
>Any ideas/suggestions/etc will be much appreciated. Thanks in advance...
Unfortunately, the solution is not as simple as you would like.
matherr() only deals with the errors that it is documented to deal
with. Basically, it is only called when an error is generated within
the trig/exponential functions.
To handle divide by zero and a host of other problems, you must set
up a signal handler for SIG_FPE (see signal()). This also requires
careful use of setjmp() and longjmp(). Which can be truly a pain in
the neck!
Pete
--
Peter Holzmann, Octopus Enterprises |(if you're a techie Christian & are
19611 La Mar Ct., Cupertino, CA 95014 |interested in helping w/ the Great
UUCP: {hpda,pyramid}!octopus!pete |Commission, email dsa-contact@octopus)
DSA office ans mach=408/996-7746;Work (SLP) voice=408/985-7400,FAX=408/985-0859
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads