problem trapping floating point overflows

Scott Pace scott at othervax.UUCP
Fri Aug 23 01:05:07 AEST 1985


If I compile and run the following program, it will continue until
a floating point overflow occurs and will then go and proccess
the interrupt routine. However, it seems that the return from the
interrupt routine is returning to the start of the instruction
which caused the overflow in the first place. Therefore, the program
just goes into an infinite loop printing the overflow message.
What exactly is happening here or what am I doing wrong ? Any help
greatly appreciated.

By the way, this is on a VAX11/780 running 4.1BSD


#include <signal.h>

int fpe_flag = 0;

main()
{
    double a = 1.0,b = 2.0;
    int fltover();

    sigset(SIGFPE,fltover);
    for (;;) {
	a *= b;
	if (fpe_flag)
	    exit(1);
    }
}

fltover()
{
    printf("Floating point overflow\n");
    fpe_flag = 1;
}


Cheers,
	Scott Pace, Philips Info. Sys. Ltd., Montreal.

	...!philabs!micomvax!othervax!scott



More information about the Comp.lang.c mailing list