Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting compiler versions during compile time

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.

like image 408
Cthutu Avatar asked Aug 28 '10 22:08

Cthutu


People also ask

How do I find my compiler version?

Type “gcc –version” in command prompt to check whether C compiler is installed in your machine. Type “g++ –version” in command prompt to check whether C++ compiler is installed in your machine.

How do I know my C++ compiler version?

So if you ever need to check the version of the GCC C++ compiler that you have installed on your PC, you can do it through the command prompt by typing in the single line, g++ --version, and this will return the result.

How do I know what version of gcc is binary?

comment section from the binary to find the version string. Use objdump and add --section to specify section name. For example, if your compiled a program named foo in the source dir, you can run the following commands to get GCC's version info: $ objdump -s --section .


1 Answers

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__
like image 66
Stephen Gennard Avatar answered Nov 06 '22 11:11

Stephen Gennard