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

南楼画角 提交于 2019-12-01 09:42:55

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!