Does FENV_ACCESS pragma exist in C++11 and higher?

后端 未结 1 1307
名媛妹妹
名媛妹妹 2021-01-14 23:56

Reading a bug report for clang not supporting FENV_ACCESS pragma I\'ve come across a comment:

Setting the rounding mode without using #pragma ST

相关标签:
1条回答
  • 2021-01-15 00:47

    I searched the 2015 standard draft text and found no occurrences of FENV_ACCESS. http://cppreference.com also has nothing about it.

    However, http://cplusplus.com does mention it (since it is not in the standard I think we must assume that this is advisory information at best):

    http://www.cplusplus.com/reference/cfenv/FENV_ACCESS/

    Quoting from cplusplus.com: (emphasis mine)

    If set to on, the program informs the compiler that it might access the floating-point environment to test its status flags (exceptions) or run under control modes other than the one by default.

    If set to off, the compiler may perform certain optimizations that can subvert these tests and mode changes, and thus accessing the floating-point environment in the cases described above, causes undefined behavior.

    Whether the state of this pragma by default is on or off depends on the compiler settings and library implementation.

    Given the unsettling lack of clarity, I would want to avoid its use if at all possible.

    As ever, if the use was unavoidable I'd want to encapsulate it into one class that I can specialise and test for each architecture.

    And then document the existence of this class and the trouble it may cause if the compiler, environment or library implementation is upgraded.

    Update:

    There is a very brief mention of the header in the c++ standard:

    § 26.3 The floating-point environment [cfenv]

    ...

    2 The header defines all functions, types, and macros the same as Clause 7.6 of the C standard.

    Update:

    Further information here: http://en.cppreference.com/w/cpp/preprocessor/impl

    My reading of this is that the pragma is defined by the C11 standard, not the C++11 standard. Therefore use in a c++ program is strictly implementation/un-defined.

    0 讨论(0)
提交回复
热议问题