This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

I want my FPE!

I would like to get control when floating-point exceptions occur, but the simple
approach doesn't seem to work; see the STC below.  It shows SIGSEGV can be
trapped but not SIGFPE.  In another experiment I tried extending libsigsegv to
handle FP exceptions but got the same results.

Is there something I need to do to "condition" the Cygwin environment to
generate FP exceptions?  I saw the code in winsup/something/or/other to map x86
FP exceptions to SIGFPE but it seems somehow the exceptions aren't being
generated in the first place.
Thanks much,


#include <setjmp.h>
#include <signal.h>
#include <stdio.h>

jmp_buf trapoline;

void segv_handler(int x)
    puts("SIGSEGV handled, continuing");
    longjmp(trapoline, 1);

void fpe_handler(int x)
    puts("SIGFPE handled, continuing");
    longjmp(trapoline, 2);

int main()
    signal(SIGSEGV, segv_handler);
    signal(SIGFPE, fpe_handler);

    switch(setjmp(trapoline)) {
        case 0:
            // first, force a SIGSEGV
            printf("%X\n", *(int *) 42);

        case 1:
            // second, force a SIGFPE
            printf("%f\n", 1E200 * 1E200);

        case 2:
            // all done

    return 0;

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]