Is there any way to know if I'm compiling under Microsoft Visual Studio 2008 ?
In visual studio, go to help | about and look at the version of Visual Studio that you're using to compile your app.
_MSC_VER should be defined to a specific version number. You can either #ifdef on it, or you can use the actual define and do a runtime test. (If for some reason you wanted to run different code based on what compiler it was compiled with? Yeah, probably you were looking for the #ifdef. :))
I was talking from the code's "point of view" . I would like to add a #ifdef , that would change a bit the code , if compiling under WinCE . There are a couple of methods that are different from the PC version.
_MSC_VER
is what you need. You can also examine visualc.hpp in any recent boost install for some usage examples.
Some values for the more recent versions of the compiler are:
MSVC++ 9.0 _MSC_VER = 1500
MSVC++ 8.0 _MSC_VER = 1400
MSVC++ 7.1 _MSC_VER = 1310
MSVC++ 7.0 _MSC_VER = 1300
MSVC++ 6.0 _MSC_VER = 1200
MSVC++ 5.0 _MSC_VER = 1100
The version number above of course refers to the major version of your Visual studio you see in the about box, not to the year in the name.
This is a little old but should get you started:
//******************************************************************************
// Automated platform detection
//******************************************************************************
// _WIN32 is used by
// Visual C++
#ifdef _WIN32
#define __NT__
#endif
// Define __MAC__ platform indicator
#ifdef macintosh
#define __MAC__
#endif
// Define __OSX__ platform indicator
#ifdef __APPLE__
#define __OSX__
#endif
// Define __WIN16__ platform indicator
#ifdef _Windows_
#ifndef __NT__
#define __WIN16__
#endif
#endif
// Define Windows CE platform indicator
#ifdef WIN32_PLATFORM_HPCPRO
#define __WINCE__
#endif
#if (_WIN32_WCE == 300) // for Pocket PC
#define __POCKETPC__
#define __WINCE__
//#if (_WIN32_WCE == 211) // for Palm-size PC 2.11 (Wyvern)
//#if (_WIN32_WCE == 201) // for Palm-size PC 2.01 (Gryphon)
//#ifdef WIN32_PLATFORM_HPC2000 // for H/PC 2000 (Galileo)
#endif
Yep _MSC_VER is the macro that'll get you the compiler version.
You can use code like this:
#if (_MSC_VER >= 1500 && _MSC_VER < 1600)
// ... Do VC9/Visual Studio 2008 specific stuff
#endif