Thread: Comeau online compiler and std::sqrt

  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,392

    Comeau online compiler and std::sqrt

    I would like an opinion concerning this program:
    Code:
    #include <cmath>
    
    int main()
    {
        double x = 0.0;
        x = std::sqrt(x);
    }
    The MinGW port of g++ 3.4.5 finds no fault with the above program. The Comeau online compiler, on the other hand, fails to compile it, citing this error:
    Code:
    MODE:strict errors C++ C++0x_extensions
    
    "ComeauTest.c", line 6: error: more than one instance of overloaded function
              "std::sqrt" matches the argument list, the choices that match are:
                function "std::sqrt(float)"
                function "std::sqrt(long double)"
                The argument types that you used are: (double)
          x = std::sqrt(x);
              ^
    
    1 error detected in the compilation of "ComeauTest.c".
    Checking the C++ Standard, I see:
    Quote Originally Posted by C++03 Section 26.5 Paragraph 5
    In addition to the double versions of the math functions in <cmath>, C++ adds float and long double overloaded versions of these functions, with the same semantics.
    I conclude then that the error is due to a missing double sqrt(double) version of std::sqrt, and thus is a bug in the standard library implementation used by the Comeau online compiler. Am I correct?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You are correct.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed