5

Recently, I am doing a job about porting. I encountered such a problem: Some Windows API, such as _clearfp(), _statusfp() etc, then I can't find the corresponding functions in Linux.

So I am here to ask for help.

Gareth McCaughan
  • 19,888
  • 1
  • 41
  • 62
Charles
  • 175
  • 1
  • 8

1 Answers1

6

You would need a POSIX system, or a C99 compiler that supported Annex F of the C99 Standard. You can test if Annex F is supported by checking if the macro __STDC_IEC_559__ is defined. The relevant functions would be found in <fenv.h>.

int feclearexcept(int excepts); // clears exceptions (returns 0 on success)
int fetestexcept(int excepts);  // returns exceptions that are set

The exceptions passed in as excepts, and returned by fetestexcept, is a bitmask that can be test against the following macros:

FE_DIVBYZERO
FE_INEXACT
FE_INVALID
FE_OVERFLOW
FE_UNDERFLOW
FE_ALL_EXCEPT

The last macro, FE_ALL_EXCEPT, is just the bitwise-or of all the macros above it.

jxh
  • 69,070
  • 8
  • 110
  • 193
  • [``](http://pubs.opengroup.org/onlinepubs/009604599/basedefs/fenv.h.html) is actually (also) POSIX, so should be portable across Unix systems. – rubenvb May 31 '13 at 08:43
  • Thanks a lot. Would you give me some use case about the functions? – Charles May 31 '13 at 09:30
  • @rubenvb: Well, it's POSIX since POSIX includes ISO C; recent POSIX versions include C99 and hence also fenv.h. – janneb May 31 '13 at 18:44
  • 1
    @janneb: I am basing the way I answer the question from [this](http://stackoverflow.com/q/16700541/315052). – jxh May 31 '13 at 18:55
  • @jxh:I solved the problem with your method. Very thanks for your help. – Charles Jun 03 '13 at 02:26