如何确定VS编译器版本--_MSC_VER || #if _MSC_VER 1000 #pragma once #endif
如何確定VS編譯器版本
_MSC_VER是MSVC編譯器的內置宏,定義了編譯器的版本,_MSC_VER 值對應版本關系
 MSVC++ 11.0 _MSC_VER = 1700 (Visual Studio 2012)??
 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 (Visual Studio 2002)?
 MSVC++ 6.0 _MSC_VER = 1200??
 MSVC++ 5.0 _MSC_VER = 1100
 ?
 example:
 #if (_MSC_VER == 1300)? //vc7??(Visual Studio 2002)?
 ? ? #import "acax16ENU.tlb" no_implementation raw_interfaces_only named_guids
 #elif (_MSC_VER == 1200)? //vc6
 ? ? #import "acad.tlb" no_implementation raw_interfaces_only named_guids
 #elif (_MSC_VER == 1400) //vc8??(Visual Studio 2005) ?
 ? ? #import "acax17ENU.tlb" no_implementation raw_interfaces_only named_guids
 #elif (_MSC_VER == 1500) //vc9 ?(Visual Studio 2008) ?
 ? ? #import "acax18ENU.tlb" no_implementation raw_interfaces_only named_guids
 #endif
 
 在程序中加入_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
 
 
==================================================================================================================
#if _MSC_VER > 1000
#pragma once
#endif
解釋:
 這是微軟的預編譯控制。
 在_MSC_VER較小時,它對一些東西的支持與新版不同
 
 _MSC_VER分解如下:
MS:Microsoft(微軟)的簡寫
C:MSC就是Microsoft出的C編譯器。
VER:Version(版本)的簡寫。
全部加在一起就是:Microsoft的C編譯器的版本
 
 
#pragma once???
指示這個文件在編譯時只被編譯器包括一次!一般用到.h中防止文件被重復包括!???
 
 #if _MSC_VER > 1000?
是指如果vc編譯器的版本大于1000則這個語句被編譯!大概小于1000的版本不支持#pragma
once這個語句
?
很多頭文件中有
 #if _MSC_VER > 1000
 #pragma once
 #endif // _MSC_VER > 1000
 _MSC_VER 定義編譯器的版本,VC++6.0就是1200??
 #if?? _MSC_VER?? >?? 1000的意思就是如果編譯器版本高于1000(VC++5.0)
總結
以上是生活随笔為你收集整理的如何确定VS编译器版本--_MSC_VER || #if _MSC_VER 1000 #pragma once #endif的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: LFW人脸数据集测试协议及编程实现
- 下一篇: vim插件-对齐插件tabular
