Discussion:
Borland compiler predefined macros.
(too old to reply)
Jason Cipriani
2008-01-22 21:15:45 UTC
Permalink
Five questions:

What macro can I check for to see if a Borland C++ compiler is being used?
What about checking the version of the compiler? (Analogous to _MSC_VER in
Visual C++).

How can I check if Borland C++ language extensions are enabled, or,
alternatively, which "Compliance" option is set in the C++ Compiler options?
(Analogous to _MSC_EXTENSIONS with the MS compiler).

How can I check for to see if VCL support is enabled? What about checking
the version of VCL? (Analogous to _MFC_VER with the MFC).

Thanks!
Jason
Alex Bakaev [TeamB]
2008-01-22 22:11:56 UTC
Permalink
Post by Jason Cipriani
What macro can I check for to see if a Borland C++ compiler is being used?
What about checking the version of the compiler? (Analogous to _MSC_VER in
Visual C++).
__BORLANDC__ or __TURBOC__
Post by Jason Cipriani
How can I check if Borland C++ language extensions are enabled, or,
alternatively, which "Compliance" option is set in the C++ Compiler options?
(Analogous to _MSC_EXTENSIONS with the MS compiler).
I think there is a way to use #pragma to check if an option is set (in
this case Borland language extensions).
Post by Jason Cipriani
How can I check for to see if VCL support is enabled? What about checking
the version of VCL? (Analogous to _MFC_VER with the MFC).
See if VCL_H is defined or not. VCL support is always available. This
macro shows if VCL headers are included or not.


.a
Remy Lebeau (TeamB)
2008-01-22 23:48:48 UTC
Permalink
Post by Alex Bakaev [TeamB]
I think there is a way to use #pragma to check if an option is
set (in this case Borland language extensions).
Ah, that is a good point, I forgot about that. You are probably thinking of
#pragma defineonoption.


Gambit
Jason Cipriani
2008-01-23 02:15:57 UTC
Permalink
Thanks Alex and Remy; and #pragma defineonoption worked great for the
language extensions. WRT checking for VCL support, it's safe to assume,
then, in portable code, that if the Borland compiler is being used, VCL
headers are present and VCL is supported? As in:

#if (__BORLANDC__ > 0x560)
#include <vcl.h>
// vcl stuff
#else
// whatever other non-vcl alternative
#endif

Has VCL been included with Borland compilers and runtime forever? Or is
there a minimum value of __BORLANDC__?

Thanks,
Jason
Remy Lebeau (TeamB)
2008-01-23 07:02:33 UTC
Permalink
WRT checking for VCL support, it's safe to assume, then,
in portable code, that if the Borland compiler is being used,
VCL headers are present and VCL is supported?
No, that assumption is not correct. Borland's compiler is capable of
compiling non-VCL C++ code as well, and VCL can be turned off when producing
Console and DLL projects. You can't just blindly #include the vcl.h header
by itself. There are startup object files that have to be linked into the
project as well in order for the VCL to work properly.
Has VCL been included with Borland compilers and runtime forever?
No.
Or is there a minimum value of __BORLANDC__?
C++Builder v1.0, which was 0x510.


Gambit
Jason Cipriani
2008-01-23 08:44:43 UTC
Permalink
Thanks for your reply.
Post by Remy Lebeau (TeamB)
No, that assumption is not correct. Borland's compiler is capable of
compiling non-VCL C++ code as well, and VCL can be turned off when producing
Console and DLL projects. You can't just blindly #include the vcl.h header
by itself. There are startup object files that have to be linked into the
project as well in order for the VCL to work properly.
I see; let me rephrase the question: Let's say I was writing some
hypothetical portable piece of code, and I wanted some precompiler logic
that said, I dunno, if I'm using the Borland compiler and VCL is there, use
TMutex, if I'm using the Microsoft compiler and MFC is around, then use
CMutex, otherwise use CreateMutex. Is this what I would do:

#if defined(__BORLANDC__) && (__BORLANDC >= 0x510)
# include <vcl.h>
// TMutex-y code
#elif defined(_MFC_VER)
# include <afxmt.h>
// CMutex-ish code
#else
# include <windows.h>
// CreateMutex-esque code
#endif

Yes, the example is ridiculously contrived. Yes, there are other libs to
link in.

In other words, you said that 0x510 is the first version where VCL was
around, and also implied that just because the version is 0x510 or greater,
that doesn't necessarily mean vcl.h and the VCL libraries are installed on
the system -- so, is there any way to detect if the VCL headers and
libraries are present on the system using nothing but precompiler macros
defined by the Borland compiler?

Thanks again,
Jason
Remy Lebeau (TeamB)
2008-01-23 10:09:39 UTC
Permalink
Post by Jason Cipriani
I see; let me rephrase the question: Let's say I was writing some
hypothetical portable piece of code, and I wanted some precompiler
logic that said, I dunno, if I'm using the Borland compiler and
VCL is there, use TMutex
You already know the answer to that.

If you really want portable code (well, for Windows platforms, anyway)
without all the fuss, why not just use CreateMutex() by itself and ignore
TMutex and CMutex altogether? You are tripling your workload to accomplish
the same thing.
Post by Jason Cipriani
you ... implied that just because the version is 0x510 or greater,
that doesn't necessarily mean vcl.h and the VCL libraries are
installed on the system
That is not what I said. I said that the VCL can be disabled on a
per-project basis. That has nothing to do with its files being installed or
not.
Post by Jason Cipriani
so, is there any way to detect if the VCL headers and libraries are
present on the system using nothing but precompiler macros defined
by the Borland compiler?
No. The vcl.h header file must be included in all VCL-aware code. You
either write VCL code or you don't. It will either compile or it won't. If
it does, then vcl.h defines VCL_H, which the rest of your code can test for.


Gambit
Jason Cipriani
2008-01-23 15:08:27 UTC
Permalink
Thanks for your reply.
... the VCL can be disabled on a
per-project basis.
The vcl.h header file must be included in all VCL-aware code. You
either write VCL code or you don't. It will either compile or it won't.
If
it does, then vcl.h defines VCL_H, which the rest of your code can test for.
I understand. The MS compiler knows (well, assumes) that the MFC headers and
libraries are present on the system (and defines _MFC_VERSION accordingly)
because the compiler comes in the platform SDK package, and so certain
versions come with MFC. That's how you can tell if it's OK to include MFC
headers and use MFC libs using only precompiler defines; of course, it
assumes you didn't delete any files from the platform SDK you installed.
That's why I was wondering. The Borland compiler does not do that.

Just out of curiosity, off topic, is VCL available separately (either free
or for $$$), so if you have the free Borland compiler and you'd like to use
VCL, but you don't want to use C++ Builder/Delphi/whatever, you can get it?

Jason

Leo Siefert
2008-01-23 13:38:22 UTC
Permalink
Post by Jason Cipriani
Has VCL been included with Borland compilers and runtime
forever? Or is there a minimum value of __BORLANDC__?
In addition to what others have said, note that the free commandline
compiler (matches the one shipped with BCB5) is supplied without any
vcl files, so you are likely to find a fair number of Borland compiler
users without vcl available.

- Leo
Remy Lebeau (TeamB)
2008-01-22 23:47:21 UTC
Permalink
Post by Jason Cipriani
What macro can I check for to see if a Borland C++ compiler is being used?
__BORLANDC__
Post by Jason Cipriani
What about checking the version of the compiler?
__BORLANDC__ is a numerical value, ie:

#if (__BORLANDC__ > 0x560)
// BCB 6 or higher
#endif
Post by Jason Cipriani
How can I check if Borland C++ language extensions are enabled
or, alternatively, which "Compliance" option is set in the C++ Compiler
options?
I have no clue.
Post by Jason Cipriani
How can I check for to see if VCL support is enabled?
There is no compiler-produced macro for that. However, all VCL-enabled code
must include VCL.h anyway, so you can check for VCL/h's "VCL_H" header
guard, ie:

#ifdef VCL_H
// can use VCL code here
#endif
Post by Jason Cipriani
What about checking the version of VCL?
There is nothing available for that. You have to use the compiler version
instead.


Gambit
Loading...