Let's take the following program:
#include <stdio.h>
#include <fenv.h>
int main (void)
{
fenv_t e;
printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
feenableexcept (FE_INVALID);
printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
fegetenv (&e);
printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
fesetenv (&e);
printf ("%d\n", fegetexcept () & FE_INVALID ? 1 : 0);
}
I expect it to output “0 1 1 1”: i.e., once I enable the FE_INVALID
exception, a call to fegetenv
, or fesetenv
with the same environment, should not modify it.
This works as expected on i386-linux, but on x86_64-linux (in 64-bit mode), I get “0 1 0 1”. That is, the call to fegetenv
clears the exceptions mask.
I don't see anywhere that it is documented, or even allowed behavior under C99. I can confirm it under glibc-2.5 and glib-2.13.
Can someone test it on a recent glibc? Am I right in thinking it's a bug?
Well, I've filed a bug in the glibc bug database, which has been confirmed by one of the developers. I guess that's proof enough that it is, indeed, a bug in glibc.