在编译期间检测编译器版本

编程入门 行业动态 更新时间:2024-10-13 14:25:04
本文介绍了在编译期间检测编译器版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个问题和一个参考,我希望人们可以建立在这一点上,以便它可以由有类似问题的人重复使用。

如何我们可靠地检测一个特定版本的C / C ++ / ObjC编译器?现在我知道Visual Studio的答案,部分知道Xcode的答案。

现在对于Visual Studio编译器,我们有_MSC_VER定义这些值:

版本1.0 800 版本2.0 900 版本2.x 900 版本4.0 1000 版本5.0 1100 版本6.0 1200 版本7.0 1300 版本7.1 1310 版本8.0 1400(Visual Studio 2005)版本9.0 1500(Visual Studio 2008)版本10.0 1600(Visual Studio 2010)版本11.0 1700(Visual Studio 2012)

现在对于Xcode编译器,我们有这个定义:

__ APPLE_CC__ pre>

但是我设法通过google找到的唯一值(Mac文档似乎没有这些值):

Xcode 3.0 5465 Xcode 3.1 5470 Xcode 3.1(GCC 4.2)5553 Xcode 3.2.3 5664从我自己的编译器)

任何人可以完成此列表或提供链接到完整的列表?

解决方案

作为一个已经移植超过他的公平份额的'C',我们可以为其他编译器提供信息。我可以看到你是从哪里来的,所以这里有一些让我们开始:

对于IBM CL / C ++编译器产品:

__ xlc__ - 格式为VRMF例如:9.0.0.0 __IBMCPP__格式为整数,如VRM,例如:V9.0为900 __IBMC__ - 格式是一个整数作为VRM,,它指示编译器作为VRM的级别:< 200是C Set / 2 < 300是C Set ++ 否则是Visual Age C ++ V.M.C 其中V =版本,M =释放,M =修改和F =修复级别。

对于Borland C:

___ BORLANDC__ ??

对于GNU C:

__ GNUC__ ??

对于Watcon C:

__ WATCOMC__

This is both a question and a reference and I am hoping that people can build upon this so that it can be reused by people with similar questions.

How can we reliably detect a particular version of a C/C++/ObjC compiler? Now I know the answer for Visual Studio and partially know the answer for Xcode.

Now for the Visual Studio compiler we have _MSC_VER which is defined with these values:

Version 1.0 800 Version 2.0 900 Version 2.x 900 Version 4.0 1000 Version 5.0 1100 Version 6.0 1200 Version 7.0 1300 Version 7.1 1310 Version 8.0 1400 (Visual Studio 2005) Version 9.0 1500 (Visual Studio 2008) Version 10.0 1600 (Visual Studio 2010) Version 11.0 1700 (Visual Studio 2012)

Now for the Xcode compiler we have this define:

__APPLE_CC__

But the only values I've managed to find via google (Mac docs don't seem to have these values) are:

Xcode 3.0 5465 Xcode 3.1 5470 Xcode 3.1 (GCC 4.2) 5553 Xcode 3.2.3 5664 (Got this value from my own compiler)

Can anyone complete this list or provide links to a full list? And maybe we can provide information for other compilers too.

解决方案

As someone who has ported more than his fair share of 'C' around, I can see were you are coming from, so here is some to get us started:

For IBM CL/C++ compiler product:

__xlc__ - Format is V.R.M.F eg: "9.0.0.0" __IBMCPP__ Format is an integer as VRM eg: V9.0 is 900 __IBMC__ - Format is an integer as VRM, which indicates the level of compiler as VRM as: < 200 is C Set/2 < 300 is C Set++ otherwise is Visual Age C++ V.M.C where V=version, M=release, M=modification and F=fix level.

For Borland C:

___BORLANDC__ ??

For GNU C:

__GNUC__ ??

For Watcon C:

__WATCOMC__

更多推荐

在编译期间检测编译器版本

本文发布于:2023-11-07 00:26:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译器   版本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!