Next: Nonportable Conversions, Previous: POSIX Standard, Up: Missing Features
The gcc backend and, consequently, g77, currently provides no general control over whether or not floating-point exceptions are trapped or ignored. (Ignoring them typically results in NaN values being propagated in systems that conform to IEEE 754.) The behavior is normally inherited from the system-dependent startup code, though some targets, such as the Alpha, have code generation options which change the behavior.
Most systems provide some C-callable mechanism to change this; this can
be invoked at startup using gcc's constructor
attribute.
For example, just compiling and linking the following C code with your
program will turn on exception trapping for the “common” exceptions
on a GNU system using glibc 2.2 or newer:
#define _GNU_SOURCE 1 #include <fenv.h> static void __attribute__ ((constructor)) trapfpe () { /* Enable some exceptions. At startup all exceptions are masked. */ feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW); }
Assuming the above source is in file trapfpe.c, then compile this routine as follows:
gcc -c trapfpe.c
and subsequently use it by adding trapfpe.o to the g77 command line when linking.