I apologize for asking a question that has been asked numerous times before. But after several searches, I realize that I may have a fundamental misunderstanding between how FPEs are to be treated in C/C++ vs. how they are treated in Fortran.
In Fortran (GNU fortran to be precise), if one wants to trap a floating point exception (use of a NAN for example), the compiler flag -ffpe-trap=invalid does the trick. The floating point exception is raised as soon as the offending statement has been executed.
In C (GNU gcc), however, this does not seem to be the case. Even more annoying (but perhaps not surprising) is that same fortran code, when called from a C main does not raise an exception (and halt execution), whereas it does when called from a Fortran main program. And this seems to be independent of whether a C or gfortran linker is used.
After much searching and reading, I see that there is C/C++ functionality available in fenv.h that suggests the "C way" of handling exceptions. I see that I can set exception flags and later check to see if exceptions have been raised. I can see how this approach might give one more flexibility over how exceptions are handled. Is this the "best practice" way of handling exceptions in C? For scientific programming (where C is often used to call fortran code) it seems inconvenient to have to have some advanced knowledge of where the exceptions might be occurring.
Is there no (straightforward) way in C to have the code that halts at the first appearance of an exception? Or is there another paradigm when it comes to exception handling in C that I am not fully grasping?