Archive for the ‘Uncategorized’ Category

Issues with Visual Studio

Posted: April 11, 2013 in Uncategorized

Unlike the other C compiler such as GCC & MingW which implements the C99 standard, Visual Studio only implements C89. As I recently compiled some C (not C++) code under VS2010 with errors, I am concerned about this.

The issue is that INFINITE, NAN, isnan() are undeclared in the <math.h> library which comes with Visual Studio. Here, a workaround is proposed for each of them.

  • Workaround for INFINITE:
  • Workaround for NAN:
#ifdef WIN32
    #ifndef NAN
        static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
        #define NAN (*(const float *) __nan)
  • Workaround for isnan():

Visual Studio comes with another function _isnan() as a replacement for isnan().

Additionally, some essential math constants – M_E, M_PI, M_LN1, M_LN10, etc – are not defined by default. To use the definitions, add the following line before you include <math.h>: