9

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.

Cthutu
  • 8,713
  • 7
  • 33
  • 49
  • 2
    Neither Visual Studio nor Xcode are compilers - you shouldn't care about their version. – alternative Aug 28 '10 at 22:52
  • 3
    @mathepic I'm as pedantic as the next guy, but really? VS comes with a specific version of the frontend compilers for each revision of the IDE, and exposes that version through _MSC_VER; that's what he wants – Michael Mrozek Aug 28 '10 at 22:54
  • 1
    Let me make myself clear then. Yes they are both IDEs but they both packaged with their own compilers, which is what I was talking about. I hoped that was clear from my message. – Cthutu Aug 28 '10 at 22:57
  • 2
    Maybe you should make the language obvious and talk in terms of C++ compilers, not IDEs. VS comes packaged with several compilers (C++, VB.NET, C#, F#, maybe others). I believed the same goes for XCode (C++, Objective-C, maybe others). – R. Martinho Fernandes Aug 28 '10 at 23:01
  • To add complexity, XCode can be used with both GCC and LLVM, and arbitrary versions of these (almost). You should never care about the XCode version, instead detect the compiler (GCC/LLVM) and version. And neither XCode nor VS are compilers. – You Aug 28 '10 at 23:09
  • 2
    People are so pedantic on this site :) I've edited the original question to say the Xcode compiler. What more do you guys need? I am assuming that people have a modicum of intelligence and recognise what these defines are about. If people know about __APPLE_CC__ and do a google search and come up with this page and find the numbers they are looking for then that would be great! But you have a good point about LLVM. Does LLVM that is packaged with Xcode have different __APPLE_CC__ values or not? – Cthutu Aug 28 '10 at 23:33
  • 1
    And what's more, I think of Visual Studio the IDE and its compiler as one of the same thing since you rarely seperate them. The question is not about whether you know the difference between a compiler and an IDE. The question is about knowing the values of the predefined macros that are defined with the compilers. Please exercise some common sense here. – Cthutu Aug 28 '10 at 23:35
  • Well, for one, its better to use `__GNUC__` and `__GNUC_MINOR__` instead of the `xcode` (and whatever the coresponding macro is for `clang` if you are using LLVM). That'll work on the terminal too. – alternative Aug 28 '10 at 23:41
  • see also [How to Detect if I'm Compiling Code With Visual Studio 2008?](http://stackoverflow.com/q/70013) – Michael Freidgeim May 22 '16 at 08:05

2 Answers2

1

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__
Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
Stephen Gennard
  • 1,910
  • 16
  • 21
  • Do you happen to know how to get the same information about C# compilers? In VS for C# the _MSC_VER is no longer available. What is? – Jesse Chisholm Jun 25 '12 at 20:12
  • I do not know any pre-defines in Microsoft C# compiler but the mono compiled does have '__MonoCS__' which has provided to be handy.. (ohh you do have DEBUG) – Stephen Gennard Jun 25 '12 at 21:40
0

There is a table of this information here:

https://sourceforge.net/p/predef/wiki/Compilers/

Sadly, It appears that MacOS defines __clang__, __GNUCC__ and __llvm__ so this information can get a little confused.

But usually, only one set of information applies.

Jesse Chisholm
  • 3,857
  • 1
  • 35
  • 29