_MSC_VER詳細介紹
轉自:http://www.cnblogs.com/braver/articles/2064817.html
_MSC_VER是微軟的預編譯控制。
_MSC_VER可以分解為:
MS:Microsoft的簡寫。
C:MSC就是Microsoft的C編譯器。
VER:Version的簡寫。
_MSC_VER的意思就是:Microsoft的C編譯器的版本。
微軟不同時期,編譯器有不同的版本:
MS VC++10.0 _MSC_VER=1600
MS VC++9.0 _MSC_VER=1500
MS VC++8.0 _MSC_VER=1400
......
其中MS VC++10.0就是Visual C++ 2010,MS VC++9.0就是Visual C++2008,MS VC++8.0就是Visual C++2005
在程序中加入_MSC_VER宏可以根據編譯器版本讓不同版本的編譯器選擇性地編譯一段程序。
查看編譯的版本信息,可以在Command line里敲 cl /?
文章二
_MSC_VER定義編譯器的版本。常見編譯器版本_MSC_VER值:
MSVC++ 11.0 _MSC_VER = 1700 (Visual Studio 2011)
MSVC++ 10.0 _MSC_VER = 1600 (Visual Studio 2010)
MSVC++ 9.0 _MSC_VER = 1500 (Visual Studio 2008)
MSVC++ 8.0 _MSC_VER = 1400 (Visual Studio 2005)
MSVC++ 7.1 _MSC_VER = 1310 (Visual Studio 2003)
MSVC++ 7.0 _MSC_VER = 1300
MSVC++ 6.0 _MSC_VER = 1200
MSVC++ 5.0 _MSC_VER = 1100
在程序中加入_MSC_VER宏可以根據編譯器版本讓編譯器選擇性地編譯一段程序。例如一個版本編譯器產生的lib文件可能不能被另一個版本的編譯器調用,那么在開發應用程序的時候,在該程序的lib調用庫中放入多個版本編譯器產生的lib文件。在程序中加入_MSC_VER宏,編譯器就能夠在調用的時根據其版本自動選擇可以鏈接的lib庫版本,如下所示。
#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
