Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
612 views
in Technique[技术] by (71.8m points)

c++ - pragma STDC FENV_ACCESS ON is not supported

I tried to slightly modify the example from the article:

#include <iostream>
#include <cfenv>

#pragma STDC FENV_ACCESS ON

int main()
{
    std::feclearexcept(FE_ALL_EXCEPT);
    //int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO);
    double x = 1.0;
    double y = 0.0;
    double result{};
    asm volatile ("fldl %1
"
                  "fdivl %2
" : "=%t"(result) : "m"(x), "m"(y) : "memory");
    std::cout << result << std::endl;
    int e = std::fetestexcept(FE_ALL_EXCEPT);
    if (e & FE_DIVBYZERO) {
        std::cout << "division by zero
";
    }
    if (e & FE_INEXACT) {
        std::cout << "inexact
";
    }
    if (e & FE_INVALID) {
        std::cout << "invalid
";
    }
    if (e & FE_UNDERFLOW) {
        std::cout << "underflow
";
    }
    if (e & FE_OVERFLOW) {
        std::cout << "overflow
";
    }
    return EXIT_SUCCESS;
}

but I get a warning (for clang++, but the same for G++ too):

warning: pragma STDC FENV_ACCESS ON is not supported, ignoring pragma [-Wunknown-pragmas]
#pragma STDC FENV_ACCESS ON
             ^
1 warning generated.

Another article reported, that the pragma is treat the class of so-called C standard pragmas, but the former mentioned article does containing the code, which uses the pragma.

Is it allowed to use the pragma in C++ code? There is <cfenv> header in C++. It alludes to the fact that this Floating-point environment is avaliable to using in C++. But this article reports about implementation dependent nature of the Floating-point environment. Is this touches upon C++?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...