Home Articles Books Downloads FAQs Tips

Q: Determine the version of the C++ compiler


Answer

Use the __BORLANDC__ define. The Borland compiler always provides this define to you. You can read the value with #if preprocessor conditionals. The value of __BORLANDC__ tells you which version of the compiler is compiling your code. The values are:

0x550  :  C++Builder 5.0 or the free BC55 compiler
0x540  :  C++Builder 4.0
0x530  :  C++Builder 3.0
0x520  :  C++Builder 1.0 and Borland C++ 5.02
0x4XX  :  Borland C++ 4.X. (I don't know the exact values)

Tip Note:
The last hex digit of __BORLANDC__ can vary. For example, my version of BCB reports 0x551. The 1 apparently signifies a patch of some kind. Beware of this variation when you read the value of __BORLANDC__

Here is an example that shows how to use these values in a preprocessor conditional.

#include <iostream>
#pragma hdrstop

using namespace std;

int main()
{
    cout << "__BORLANDC__ == 0x" << std::hex << __BORLANDC__ << endl;
    
#if   (__BORLANDC__ >= 0x560)
    cout << "It's a future version. Woohoo!"  << endl;
#elif (__BORLANDC__ >= 0x550)
    cout << "BCB5 detected."  << endl;
#elif (__BORLANDC__ >= 0x540)
    cout << "BCB4 detected."  << endl;
#elif (__BORLANDC__ >= 0x530)
    cout << "BCB3 detected."  << endl;
#else
    cout << "Very old version detected."  << endl;
#endif


    return 0;
}


Copyright © 1997-2000 by Harold Howe.
All rights reserved.