Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...