_MSC_VER超详细讲解,一看就会

_MSC_VER是微软的预编译控制。工具

_MSC_VER能够分解为:开发工具

MS:Microsoft的简写。spa

C:MSC就是Microsoft的C编译器。开发

VER:Version的简写。编译器

_MSC_VER的意思就是:Microsoft的C编译器的版本。io

微软不一样时期,编译器有不一样的版本:编译

MS VC++ 14.0 _MSC_VER = 1900 (Visual Studio 2015)
MS VC++ 12.0 _MSC_VER = 1800 (VisualStudio 2013)
MS VC++ 11.0 _MSC_VER = 1700 (VisualStudio 2012)
MS VC++ 10.0 _MSC_VER = 1600(VisualStudio 2010)
MS VC++ 9.0 _MSC_VER = 1500(VisualStudio 2008)
MS VC++ 8.0 _MSC_VER = 1400(VisualStudio 2005)
MS VC++ 7.1 _MSC_VER = 1310(VisualStudio 2003)
MS VC++ 7.0 _MSC_VER = 1300(VisualStudio .NET)
MS VC++ 6.0 _MSC_VER = 1200(VisualStudio 98)
MS VC++ 5.0 _MSC_VER = 1100(VisualStudio 97)
其中MS VC++ 14.0表示Visual C++的版本为14.0,后面括号中的Visual Studio 2015,代表该VC++包含在微软开发工具Visual Studio 2015中。

在程序中加入_MSC_VER宏能够根据编译器版本让编译器选择性地编译一段程序。例如一个版本编译器产生的lib文件可能不能被另外一个版本的编译器调用,那么在开发应用程序的时候,在该程序的lib调用库中放入多个版本编译器产生的lib文件。在程序中加入_MSC_VER宏,编译器就可以在调用的时根据其版本自动选择能够连接的lib库版本,以下所示。class

#if _MSC_VER >= 1400 // for vc8, or vc9 


  #ifdef _DEBUG 


  #pragma comment( lib, "SomeLib-vc8-d.lib" ) 


  #else if 


  #pragma comment( lib, "SomeLib-vc8-r.lib" ) 


  #endif 


  #else if _MSC_VER >= 1310 // for vc71 


  #ifdef _DEBUG 


  #pragma comment( lib, "SomeLib-vc71-d.lib" ) 


  #else if 


  #pragma comment( lib, "SomeLib-vc71-r.lib" ) 


  #endif 


  #else if _MSC_VER >=1200 // for vc6 


  #ifdef _DEBUG 


  #pragma comment( lib, "SomeLib-vc6-d.lib" ) 


  #else if 


  #pragma comment( lib, "SomeLib-vc6-r.lib" ) 


  #endif 


  #endif
程序