Consider the following code:
test-fesetexceptflag.c:
----------------
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
static void
handle_signal (int sig)
{
printf ("SIGFPE\n");
_Exit (1);
}
int main()
{
fexcept_t fexcept;
fegetexceptflag(&fexcept, FE_ALL_EXCEPT);
fesetexceptflag(&fexcept, FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
signal (SIGFPE, handle_signal);
double result = 1.0 / 0.0;
return 0;
}
----------------
It prints SIGFPE on mingw-w64, but not on MSVC and Linux/GLibc. According to
the C standard, "like fesetexcept, [fesetexceptflag] does not raise
floating-point exceptions, but only sets the state of the flags"
In addition, feholdexcept() does not enable non-stop mode (which should also
inhibit traps):
test-feholdexcept.c:
----------------
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
static void
handle_signal (int sig)
{
printf ("SIGFPE\n");
_Exit (1);
}
int main()
{
fexcept_t fexcept;
fegetexceptflag(&fexcept, FE_ALL_EXCEPT);
fesetexceptflag(&fexcept, FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
signal (SIGFPE, handle_signal);
fenv_t fenv;
feholdexcept (&fenv);
double result = 1.0 / 0.0;
return 0;
}
----------------
Luca
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public