Question

I was compiling ANSI-C in VS2012 (with _CRT_SECURE_NO_WARNINGS set) and the program uses "math.h". And I encounter the following problems:

sqrt()

The automatic checker for VS2012 will tell me there is an error

IntelliSense: more than one instance of overloaded function "sqrt" matches the argument list:

        function "sqrt(double _X)"
        function "sqrt(float _X)"
        function "sqrt(long double _X)"
        argument types are: (int)

but the project will still build. It confuses me because I think C doesn't support function overloading?

Debug with fabs()

After the project builds I tried to debug. When it runs to the line

char eq(double a, double b, double epsilon) {
    return (fabs(a - b) < epsilon); // problem
}

function, it will build but in debug mode it will generate an error page "fabs.c not found":

enter image description here

I am not sure what's going on. It seems the problem only happens in Debug mode. When I run the compiled program .exe in command line it works fine.

Was it helpful?

Solution

Your issue with sqrt() is one with Intellisense which is the code completion part of the IDE. It has nothing to do with compiling the code. It's possible that Intellisense always defaults to C++ or has no knowledge that you're compiling as C code (it uses a database of function names to lookup). Are you sure you're compiling as C? There is a flag for the compiler (that you can set in the solution, project or file properties) to force it to compile as C or C++, but it will also default to C if you use the extension ".c".

The issue with fabs() is just what happens sometimes when you try to step into code that the source is not available for, which is typically functions in the standard library and you are using the Express or Standard versions of Visual Studio. The Professional and higher products come with the source so you should be able to debug into it with those.

When you step into the function the IDE tries to show the code, does not find it then gives you an error. But you can continue to debug, just cancel the file dialog asking for the path to fabs.c and use the "Step out" and it will come back to the line of code after the function call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top