Detecting compile in Studio 2005 vs. Studio 2003 or 6.0

 I share common source code with several other projects that compile in Studio 2003, Studio 6.0, Borland, or (gasp) an embedded Green Hills compiler.

Is there a #define I can look for so that I can fix all the deprecated CRT functions when I use the code in Studio 2005 (and so I can leave the old unchanged version in place for all the other folks) Something like

#ifdef STUDIO_2005
    strcpy_s(DestString, sizeof(DestString), SourceString);
    errno_t err = fopen_s(&fp, Filename, "r");
#else // for older compilers
    strcpy_s(DestString, sizeof(DestString), SourceString);
    fp = fopen(Filename, "r");
#endif


Answer this question

Detecting compile in Studio 2005 vs. Studio 2003 or 6.0

  • Fat Dragon

    Thanks a heap!

  • vidman

    Use _MSC_VER define:

    #if _MSC_VER >= 1400
       // this is Visual C++ 2005
    #elif _MSC_VER >= 1310
       // this is Visual c++ .NET 2003
    #elif _MSC_VER > 1300
       // this is Visual C++ .NET 2002
    #endif

  • Detecting compile in Studio 2005 vs. Studio 2003 or 6.0