Search code examples
cvisual-studiovisual-studio-2010c99c89

fmax and fmin alternative in c89


When trying to compile GLFW using visual studio 2010 I got error that "error LNK2019: unresolved external symbol _fmax referenced in Error 3 error LNK2019: unresolved external symbol _fmax referenced in function _star F:\Dev\PROGS\GLFW\build\tests\cursor.obj cursor But as I heard visual studio does not support c99 .Then what is workaround to this?


Solution

  • As you said, these functions were added in C99 and C++11. Microsoft's C compiler does not support C99, but later versions of the C++ compiler do support C++11. The one bundled with Visual Studio 2013 will have these functions. I'm not sure if they're usable when you're compiling C code or not.

    If you're stuck on an older version of the compiler, like VS 2010, it's trivial to implement these functions yourself. Put them in an MSVC-compatibility header:

    #ifdef _MSC_VER
        #define INLINE __inline
    
        INLINE double fmax(double left, double right)
        { return (left > right) ? left : right; }
    
        INLINE double fmin(double left, double right)
        { return (left < right) ? left : right; }
    #endif