Using macros to judge vs compiled versions and system platforms

Source: Internet
Author: User
Tags vc9

Msc_ver defines the version of the compiler. Here are the _msc_ver values for some compiler versions (see the link to reference 2 in extended reading)

Msvc++ 12.0 _msc_ver = = 1800 (Visual Studio) msvc++ 11.0 _msc_ver = 1700 (Visual Studio) msvc++ 10.0 _msc_ver = = (Visual Studio) msvc++ 9.0  _msc_ver = = (Visual Studio) msvc++ 8.0  _msc_ver = 1400 (visual Studi O 2005) msvc++ 7.1  _msc_ver = = 1310 (Visual Studio 2003) msvc++ 7.0  _msc_ver = 1300msvc++ 6.0  _msc_ver = = 1200M svc++ 5.0  _msc_ver = = 1100

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 = =)//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 (Galileo) #e Ndif

Example2:

    #if(_msc_ver = = 1300)//VC7#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#import"acax17enu.tlb"no_implementation raw_interfaces_only named_guids#elif(_msc_ver = = 1500)//VC9#import"acax18enu.tlb"no_implementation raw_interfaces_only named_guids#endif

Adding a _msc_ver macro to a program allows the compiler to selectively compile a program based on the compiler version . For example, the Lib file generated by a version compiler may not be called by another version of the compiler, so when developing the application, a Lib file generated by multiple versions of the compiler is placed in the LIB call Library of the program. By adding the _msc_ver macro to the program, the compiler will be able to automatically select the version of the Lib library that can be linked to it at the time of invocation, as shown below.

#if_msc_ver >= 1400//for Vc8, or VC9#ifdef _DEBUG#pragmaComment (lib, "Somelib-vc8-d.lib")#elseIf#pragmaComment (lib, "Somelib-vc8-r.lib")#endif#elseIf _msc_ver >= 1310//For vc71#ifdef _DEBUG#pragmaComment (lib, "Somelib-vc71-d.lib")#elseIf#pragmaComment (lib, "Somelib-vc71-r.lib")#endif#elseIf _msc_ver >=1200//For VC6#ifdef _DEBUG#pragmaComment (lib, "Somelib-vc6-d.lib")#elseIf#pragmaComment (lib, "Somelib-vc6-r.lib")#endif#endif

Using macros to judge vs compiled versions and system platforms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.