定义系统平台编译器位数的宏版本 & Windows 及 Visual Studio 发行时间

// 参考:
// "编译器中和64位编程有关的预定义宏"
// https://blog.csdn.net/liangbch/article/details/36020391
// 《Calling conventions for different C++ compilers and operating systems》,
// Last updated 2012-02-29,By Agner Fog. Copenhagen University College.
// # 查看内置宏:
//   gcc -dM -E - < /dev/null
// # 查看系统位数
//   getconf LONG_BIT

//****************************************************************************** 
// Automated Hardware Platform Detection 
//******************************************************************************

#if defined(_M_IX86) ||  defined(__INTEL__) || 
    defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) 
  // x86 32bit
#elif defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || 
      defined(__amd64) || defined(__amd64__)
  // x86-64
#elif defined(__IA64__)
  // IA64
#elif defined(__ALPHA__)
  // DEC Alpha
#elif defined(__POWERPC__)
  // Motorola Power PC
#elif defined(__LITTLE_ENDIAN__)
  // Any other little endian
#elif defined(__BIG_ENDIAN__)
  // Any other big endian
#endif


//****************************************************************************** 
// Automated Operating System Detection 
//******************************************************************************

#if defined(__MSDOS__) || defined(_MSDOS)
  // DOS 16 bit
#elif defined(_WIN16)
  // Windows 16 bit
#elif defined(_WIN32) || defined(__WINDOWS__)
  // define something for Windows (32-bit and 64-bit, this part is common)
  #ifdef _WIN64
    // define something for Windows (64-bit only)
  #else
    // define something for Windows (32-bit only)
  #endif
#elif defined(__APPLE__) || defined(__DARWIN__) || defined(__MACH__)
  // define something for Mac OS (32-bit and 64-bit, this part is common)
  #if TARGET_IPHONE_SIMULATOR
    // iOS Simulator
  #elif TARGET_OS_IPHONE
    // iOS Device
  #elif TARGET_OS_MAC
    // Other Kinds Of Mac OS
  #endif
#elif defined(__ANDROID__)
  // android
#elif defined(__BSD__) || defined(__FREEBSD__) 
  // BSD
#elif defined(__linux__)
  // define something for linux (32-bit and 64-bit, this part is common)
  //  Linux Subsystem: Ubuntu, Solaris, Redhat, RHEL, CentOS, Fedora, Arch Linux, 
  //                   Debian, openSUSE, Flatpak, Solus*, FreeBSD*, 红旗Linux
  #ifif defined(__LP64__) || defined(__amd64) //|| defined(__amd64__)
    // define something for linux (64-bit only)
  #else
    // define something for linux (32-bit only)
  #endif
#elif defined(__OS2__)
  // OS/2
#elif defined(__unix__)// all unices not caught above
  // Unix
#elif defined(_POSIX_VERSION)
  // POSIX
#else
  // KDE Neon, Windows ICE, Windows Phone, Windows Subsystem for Linux(简称WSL), HarmonyOS
  #error "Unknown"
#endif

// Define __WIN16__ platform indicator 
#ifdef _Windows_ 
#ifndef __NT__ 
#define __WIN16__ 
#endif 
#endif

// _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 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


//****************************************************************************** 
// Automated Windows System Version Detection 
//******************************************************************************

// https://learn.microsoft.com/zh-cn/cpp/porting/modifying-winver-and-win32-winnt#更新 WINVER 和 _WIN32_WINNT
// https://blog.csdn.net/fqmsly/article/details/55046856#window的版本宏
// https://blog.csdn.net/xsm360/article/details/45057743#判断Windows版本新方法
// https://blog.csdn.net/yaowushan_xc/article/details/96828974#获取windows系统版本号
// 命令行: WinVer,Ver,SystemInfo

// sdkddkver.h 里定义了 Windows 版本宏: WINVER
// IE版本 _WIN32_IE_IEXXX 也定义在 sdkddkver.h 里面。
// 
#include <WinSDKVer.h>
#include <sdkddkver.h>

#ifndef WINVER
#ifdef _WIN32_WINNT
// set WINVER based on _WIN32_WINNT
#define WINVER          _WIN32_WINNT
#else
#define WINVER          _WIN32_WINDOWS
#endif
#endif

//下面是 Windows 10 SDK 版 sdkddkver.h(它对每个主版本的 Windows 的值进行编码)中的行:

//
// _WIN32_WINNT version constants
//
                                                   // Windows 1.0               1985年12月20日
                                                   // Windows 2.0               1987年12月9日
                                                   // Windows 3.0               1990年5月22日
                                                   // Windows NT 3.1            1993年7月27日
#define _WIN32_WINNT_NT4                    0x0400
#define _WIN32_WINNT_W95                    0x0400 // Windows 95                1995年8月24日
                                                   // Windows NT 4.0            1996年8月24日
#define _WIN32_WINNT_W98                    0x0401 // Windows 98                1998年6月25日
#define _WIN32_WINNT_WIN2K                  0x0500 // Windows 2000              2000年2月17日
#define _WIN32_WINNT_ME                     0x0500 // Windows Me                2000年9月14日
#define _WIN32_WINNT_WINXP                  0x0501 // Windows XP                2001年10月25日
#define _WIN32_WINNT_WS03                   0x0502 // Windows Server 2003       2003年4月24日
#define _WIN32_WINNT_WIN6                   0x0600 // Windows Vista
#define _WIN32_WINNT_VISTA                  0x0600 // Windows Vista             2007年1月30日
#define _WIN32_WINNT_LONGHORN               0x0600 // Windows Vista
#define _WIN32_WINNT_WS08                   0x0600 // Windows Server 2008       2008年2月27日
#define _WIN32_WINNT_WSR2                   0x0601 // Windows Server 2008 R2
#define _WIN32_WINNT_WIN7                   0x0601 // Windows 7                 2009年10月22日
                                                   // Windows Server 2012       2012年9月4日
#define _WIN32_WINNT_WIN8                   0x0602 // Windows 8                 2012年10月25号
#define _WIN32_WINNT_WINBLUE                0x0603 // Windows 8.1               2013年10月17日
                                                   // Windows 10                2015年7月29日
                                                   // Windows 11                2021年10月5日
#define _WIN32_WINNT_WINTHRESHOLD           0x0A00 /* ABRACADABRA_THRESHOLD*/
#define _WIN32_WINNT_WIN10                  0x0A00 /* ABRACADABRA_THRESHOLD*/


//
// NTDDI version constants (子版本号)
//

#define NTDDI_WINXP                         0x05010000
#define NTDDI_WINXPSP1                      0x05010100
#define NTDDI_WINXPSP2                      0x05010200
#define NTDDI_WINXPSP3                      0x05010300
#define NTDDI_WINXPSP4                      0x05010400
// ...
#define NTDDI_WIN7                          0x06010000
#define NTDDI_WIN8                          0x06020000
// ...
#define NTDDI_WIN10                         0x0A000000  /* ABRACADABRA_THRESHOLD */
#define NTDDI_WIN10_TH2                     0x0A000001  /* ABRACADABRA_WIN10_TH2 */
#define NTDDI_WIN10_RS1                     0x0A000002  /* ABRACADABRA_WIN10_RS1 */
#define NTDDI_WIN10_RS2                     0x0A000003  /* ABRACADABRA_WIN10_RS2 */
#define NTDDI_WIN10_RS3                     0x0A000004  /* ABRACADABRA_WIN10_RS3 */
#define NTDDI_WIN10_RS4                     0x0A000005  /* ABRACADABRA_WIN10_RS4 */
#define NTDDI_WIN10_RS5                     0x0A000006  /* ABRACADABRA_WIN10_RS5 */
#define NTDDI_WIN10_19H1                    0x0A000007  /* ABRACADABRA_WIN10_19H1*/
#define NTDDI_WIN10_VB                      0x0A000008  /* ABRACADABRA_WIN10_VB */

#define WDK_NTDDI_VERSION                   NTDDI_WIN10_VB /* ABRACADABRA_WIN10_VB */


//****************************************************************************** 
// Automated Compiler Detection 
//******************************************************************************

#if defined(__BORLANDC__)
  cout << "Compiler Borland C++" << endl;
#elif defined(__VECTORC__)
  cout << "Compiler Codeplay VectorC" << endl;
#elif defined(__CYGWIN__)
  cout << "Compiler Cygwin GUN C++" << endl;
#elif defined(__DMC__)
  cout << "Compiler Digital Mars" << endl;
#elif defined(__GNUC__)
  cout << "Compiler GCC" << endl;
#elif defined(__INTEL_COMPILER)
  cout << "Compiler Intel" << endl;
#elifdef _MSC_VER
  cout << "Compiler MSVC" << endl;
#elif defined(__PATHSCALE__)
  cout << "Compiler Pathscale" << endl;
#elif defined(__SYMANTECC__)
  cout << "Compiler Symantec" << endl;
#elif defined(__WATCOMC__)
  cout << "Compiler Watcom" << endl;
#endif


//****************************************************************************** 
// Automated Language Version Detection 
//******************************************************************************

/*
目前C语言的标准有:ANSI C89(等同ISO C90)、C95、C99(ISO C)、C11(C1x)、C17、C2x
目前C++语言的标准有:C++98、C++03(对98小幅修改)、C++11(C++0x,全面进化)、C++14、C++17、C++20、C++23
关于单片机 C51: https://blog.csdn.net/weixin_46251230/article/details/124506741
C++ 标准 与 各种编译器版本 的对应关系:https://en.cppreference.com/w/cpp/compiler_support
*/

// 《/Zc:__cplusplus (启用更新后的 __cplusplus 宏)》
// https://learn.microsoft.com/zh-cn/cpp/build/reference/zc-cplusplus?view=msvc-170
// /Zc:__cplusplus启用该选项后,宏报告__cplusplus的值取决于版本/std选项设置。 下表列出了该宏的可能值:
// /Zc:__cplusplus 选项      /std 选项              __cplusplus 值
//  Zc:__cplusplus           /std:c++14(默认值)   201402L
//  Zc:__cplusplus           /std:c++17            201703L
//  Zc:__cplusplus           /std:c++20            202002L
//  Zc:__cplusplus           /std:c++latest        查看文本
//  Zc:__cplusplus- (禁用)   任何值                 199711L(C++03)
//  未指定                   任何值                 199711L(C++03)      
// 在 C++03 标准中, __cplusplus 的值被预定义为 199711L,
// 在 C++11 标准中, __cplusplus 的值被预定义为 201103L.
// https://www.cnblogs.com/Braveliu/p/12219521.html     

// 检测是否支持 ISO C++11
#if __cplusplus <= 199711L && \
    (!defined(_MSC_VER) || _MSC_VER < 1600) && \
    (!defined(__GNUC__) || \
      (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40603))
  #error A C++11 compatible compiler is required for FlatBuffers.
  #error __cplusplus _MSC_VER __GNUC__  __GNUC_MINOR__  __GNUC_PATCHLEVEL__
#endif

#if defined(__linux__) || defined(__CYGWIN__) ||  defined(__MINGW32__) || defined(__unix__)
  #ifdef __GNUC__
    #ifndef __GNUC_PATCHLEVEL__
      #define __GNUC_PATCHLEVEL__ 0
      // 注意,__GNUC_PATCHLEVEL__是从gcc 3.0以后才有的  
    #endif
    #ifndef GCC_VERSION
      #define GCC_VERSION ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__)
    #endif
    // https://gcc.gnu.org/onlinedocs/gcc-5.1.0/cpp/Common-Predefined-Macros.html#Common-Predefined-Macros            
    int test()
    {
      #if GCC_VERSION > 30200
        printf("gcc version > 3.2.0\n");
      #endif
        return 0;
    }
  #endif
#endif

/*
// GCC 对C++标准 core 的支持:
// https://gcc.gnu.org/projects/cxx-status.html
// https://gcc.gnu.org/gcc-4.3/cxx0x_status.html
// http://gcc.gnu.org/releases.html
// https://blog.csdn.net/u010977122/article/details/100708274
19870322  GCC 0.9       GCC_VERSION == 900
19870523  GCC 1.0       GCC_VERSION == 10000
19871218  GCC 1.15.3    GCC_VERSION == 11503    --- 开始支持 g++  
19920920  GCC 1.42.0    GCC_VERSION == 14200
19920222  GCC 2.0       GCC_VERSION == 20000
19971203  GCC                                   --- EGCS 1.0
19990315  GCC                                   --- EGCS 1.1.2
20010316  GCC 2.95.3    GCC_VERSION == 20953
20010718  GCC 3.0       GCC_VERSION == 30000
20060306  GCC 3.4.6     GCC_VERSION == 30406
20050420  GCC 4.0.0     GCC_VERSION == 40000    --- 部分ISO C++03
20070513  GCC 4.2.0     GCC_VERSION == 40200    --- 部分ISO C++03         
20080305  GCC 4.3.0     GCC_VERSION == 40300    --- 部分ISO c++11   一项ISO c++14(Binary literals)
20120301  GCC 4.6.3     GCC_VERSION == 40603    --- 部分ISO c++11
20130531  GCC 4.8.1     GCC_VERSION == 40801    --- 全部ISO c++11   部分ISO c++14
20140422  GCC 4.9.0     GCC_VERSION == 40900    --- 部分ISO c++14   部分ISO c++17
20160803  GCC 4.9.4     GCC_VERSION == 40904
20150422  GCC 5.1       GCC_VERSION == 50100    --- 全部ISO c++14   部分ISO c++17
20171010  GCC 5.5       GCC_VERSION == 50500             
20160427  GCC 6.1       GCC_VERSION == 60100    --- 部分ISO c++17   部分ISO c++20
20181026  GCC 6.5       GCC_VERSION == 60500
20170502  GCC 7.1       GCC_VERSION == 70100    --- 全部ISO c++17   部分ISO c++20
20191114  GCC 7.5       GCC_VERSION == 70500
20180502  GCC 8.1       GCC_VERSION == 80100    --- 部分ISO c++20
20210514  GCC 8.5       GCC_VERSION == 80500
20190503  GCC 9.1       GCC_VERSION == 90100    --- 部分ISO c++20   部分ISO c++23
20220527  GCC 9.5       GCC_VERSION == 90500
20200507  GCC 10.1      GCC_VERSION == 100100   --- 部分ISO c++20   部分ISO c++23
20220728  GCC 10.4      GCC_VERSION == 100400
20210427  GCC 11.1      GCC_VERSION == 110100   --- 部分ISO c++20   部分ISO c++23
20220421  GCC 11.3      GCC_VERSION == 110300
20220506  GCC 12.1      GCC_VERSION == 120100   --- 基本ISO c++20   部分ISO c++23
20220819  GCC 12.2      GCC_VERSION == 120200
2023      GCC 13.1      GCC_VERSION == 130100   --- 部分ISO c++23
*/

/*
// GCC 对C++标准 Library 的支持:
// ... ...
*/

/*
gcc下的语言规范设置:
https://www.cnblogs.com/-colin/p/8257162.html
-std=iso9899:1990,-ansi或-std=c89 (三者完全等同)来指定完全按照c89规范,而禁止gcc对c语言的扩展。
-std=iso9899:199409 使用C95规范
-std=c99 或者 -std=iso9899:1999 使用C99规范。
-std=gnu89 使用c89规范加上gcc自己的扩展(目前默认)
-std=gnu99 使用c99规范加上gcc自己的扩展
*/

/*
// MSVC 对C++标准, C标准的支持:
// https://docs.microsoft.com/en-us/previous-versions/hh567368(v=vs.140)
// vs 内部版本对应:
// https://docs.microsoft.com/zh-cn/visualstudio/install/visual-studio-build-numbers-and-release-dates?view=vs-2019
// RTW: 网络发布版(Release To Web)
          MSC 1.0         _MSC_VER == 100                                         --- 1983.10, 基于Lattice C
          MSC 2.0         _MSC_VER == 200
          MSC 3.0         _MSC_VER == 300
          MSC 4.0         _MSC_VER == 400
          MSC 5.0         _MSC_VER == 500
          MSC 6.0         _MSC_VER == 600
          MSC 7.0         _MSC_VER == 700
          MSVC++ 1.0      _MSC_VER == 800
          MSVC++ 2.0      _MSC_VER == 900
          MSVC++ 4.0      _MSC_VER == 1000 (Developer Studio 4.0)
          MSVC++ 4.2      _MSC_VER == 1020 (Developer Studio 4.2)
          MSVC++ 5.0      _MSC_VER == 1100 (Visual Studio 97 version 5.0)
          MSVC++ 6.0      _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)
          MSVC++ 7.0      _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)
          MSVC++ 7.1      _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)
          MSVC++ 8.0      _MSC_VER == 1400 (Visual Studio 2005 version 8.0)       --- 部分ISO c++03, 部分C99
          MSVC++ 9.0      _MSC_VER == 1500 (Visual Studio 2008 version 9.0)       --- 部分ISO c++03
          MSVC++ 10.0     _MSC_VER == 1600 (Visual Studio 2010 version 10.0)      --- 部分ISO c++11, 部分C99
20121126  MSVC++ 11.0     _MSC_VER == 1700 (Visual Studio 2012 version 11.0)      --- 部分ISO c++11
20131017  MSVC++ 12.0     _MSC_VER == 1800 (Visual Studio 2013 version 12.0)      --- 部分ISO c++11
20150720  MSVC++ 14.0     _MSC_VER == 1900 (Visual Studio 2015 version 14.0)      --- 全部ISO c++11  基本完整C99
20170307  MSVC++ 14.1     _MSC_VER == 1910 (Visual Studio 2017 version 15.0)      --- 部分ISO c++14 或 c++17(可选)
          MSVC++ 14.11    _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
          MSVC++ 14.12    _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
          MSVC++ 14.13    _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
          MSVC++ 14.14    _MSC_VER == 1914 (Visual Studio 2017 version 15.7)      --- 全部ISO c++17
          MSVC++ 14.15    _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
20181113  MSVC++ 14.16    _MSC_VER == 1916 (Visual Studio 2017 version 15.9)      --- 全部ISO c++17, 部分C99
20190402  MSVC++ 14.20    _MSC_VER == 1920 (Visual Studio 2019 RTW 16.0.0)
          MSVC++ 14.21    _MSC_VER == 1921 (Visual Studio 2019 Version 16.1)
          MSVC++ 14.28    _MSC_VER == 1928 (Visual Studio 2019 Version 16.8)      --- 部分C11, 部分C17
20210810  MSVC++ 16.11    _MSC_VER == 1929 (Visual Studio 2019 Version 16.11)     --- 大多ISO c++20
20211108  MSVC++ 17.0     _MSC_VER == 1930 (Visual Studio 2022 RTW 17.0)      
          MSVC++ 17.1     _MSC_VER == 1931 (Visual Studio 2022 Version 17.1)
          MSVC++ 17.2     _MSC_VER == 1932 (Visual Studio 2022 Version 17.2)      --- 全部ISO c++20
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值