 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Rune Allnor Guest
|
Posted: Wed May 03, 2006 9:06 pm Post subject: Identifying compiler |
|
|
Hi all.
I am programming some C files that will be called from matlab.
According to the matlab documentation, a certain amount of
"voodoo" needs to be included if one uses one particular
compiler, to ensure some details to be handled correctly.
Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
- Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
Rune
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Bob Hairgrove Guest
|
Posted: Thu May 04, 2006 10:21 am Post subject: Re: Identifying compiler |
|
|
On 3 May 2006 16:02:15 -0400, "Rune Allnor" <allnor (AT) tele (DOT) ntnu.no>
wrote:
| Quote: | Hi all.
I am programming some C files that will be called from matlab.
According to the matlab documentation, a certain amount of
"voodoo" needs to be included if one uses one particular
compiler, to ensure some details to be handled correctly.
Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
- Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
Doesn't the documentation to matlab tell you what the "voodoo" is, and
how to detect when it should be used?
Most compilers (actually, all that I have ever seen) will define some
symbol which is unique to that particular compiler. Also, the symbol
will have a value which indicates which version of the compiler you
are using. So you have to check the documentation for each compiler.
Be wary of checking just _MSC_VER, however, which is defined by the
Microsoft compilers. This symbol is also defined by some other
compilers (Intel, for example) so you might need to exclude some other
symbols if you are really targeting MSVC.
--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Jack Klein Guest
|
Posted: Thu May 04, 2006 10:21 am Post subject: Re: Identifying compiler |
|
|
On 3 May 2006 16:02:15 -0400, "Rune Allnor" <allnor (AT) tele (DOT) ntnu.no>
wrote in comp.lang.c++.moderated:
| Quote: | Hi all.
I am programming some C files that will be called from matlab.
According to the matlab documentation, a certain amount of
"voodoo" needs to be included if one uses one particular
compiler, to ensure some details to be handled correctly.
Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
- Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
Rune
|
Since you decided not to name the "one particular compiler", that
makes it pretty hard to provide a specific answer. Of course, if you
had, it would most likely have been judged as off-topic for being
compiler specific. As it is, it's marginal, since the C++ language
itself does not define any way to do this (neither does C).
However, every C and C++ compiler I have used for at least the past 15
years has some predefined macro of its own that specifies either the
compiler "brand", the compiler version, or macros that specify both.
I would suggest you check the "particular compiler's" documentation
and see if it does this.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Aleksander Beluga Guest
|
Posted: Thu May 04, 2006 10:21 am Post subject: Re: Identifying compiler |
|
|
Rune Allnor wrote:
| Quote: | Hi all.
- Is this a good way of doing things?
Precisely good, many respectable libraries such as Boost were caught |
doing this.
| Quote: | - Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
IMHO, documentation should tell about that in more details but Google |
says that define for BorlandC++ is "__BORLANDC__).
Chip. http://slashdot.org/~MrChipset/journal
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Thu May 04, 2006 10:21 am Post subject: Re: Identifying compiler |
|
|
Rune Allnor wrote:
| Quote: | I am programming some C files that will be called from matlab.
According to the matlab documentation, a certain amount of
"voodoo" needs to be included if one uses one particular
compiler, to ensure some details to be handled correctly.
Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
|
It's essentially the only commonly acceptable way of introducing
compiler-specific code.
| Quote: | - Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
RTFM. Something like "predefined macros" or "compiler-defined
macros".
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Gene Bushuyev Guest
|
Posted: Thu May 04, 2006 10:21 am Post subject: Re: Identifying compiler |
|
|
"Rune Allnor" <allnor (AT) tele (DOT) ntnu.no> wrote in message
news:1146659199.482669.231650 (AT) v46g2000cwv (DOT) googlegroups.com...
[...]
| Quote: | Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
- Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
Each compiler has its own macros, read the compiler documentation to find out
what they are. Borland compilers define __BORLANDC__ and __BCPLUSPLUS__ macros.
--
Gene Bushuyev (www.gbresearch.com)
----------------------------------------------------------------
There is no greatness where there is no simplicity, goodness and truth. ~ Leo
Tolstoy
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Thu May 04, 2006 10:21 am Post subject: Re: Identifying compiler |
|
|
Rune Allnor wrote:
| Quote: | Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
|
In many cases, it is the least ugly way. Another way would be to write a
header for each and every compiler and somehow include that via commandline
arguments or somesuch.
| Quote: | - Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
That should be documented. However, I suggest that you take a look at a
library that is heavily cross-platform like e.g. STLport or Boost. Both of
them have a complicated framework to detect platform, compiler and
standardlibrary, including their version. The point is, sometimes there is
more to it because e.g. some compilers (in the name of compatibility) do
stupidities like invading another compiler's special signature macro or
they changed macros during their lifetime etc.
Uli
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Ivan Vecerina Guest
|
Posted: Thu May 04, 2006 9:21 pm Post subject: Re: Identifying compiler |
|
|
"Rune Allnor" <allnor (AT) tele (DOT) ntnu.no> wrote in message
news:1146659199.482669.231650 (AT) v46g2000cwv (DOT) googlegroups.com...
: Now, I wonder how I can detect at compile time if this
: compiler is used. If so, I might be able to make a header
: like
:
: #ifdef SomeCompiler
: /* voodoo to be included */
: #endif
:
: - Is this a good way of doing things?
No. But at times there is no better choice ;)
: - Where can I find out what to substitute for "SomeCompiler"
: above? The above must be valid for any Borland compiler.
Every compiler typically provides some predefined macros
allowing identification.
Try searching for "predefined macros" in your compiler's
documentation, or on the web.
Actually, the latter brought me to:
http://groups.google.com/group/
borland.public.cppbuilder.commandlinetools/browse_thread/thread/
3f6d806e4d90a7f9/dcbae2c61957ac4%23dcbae2c61957ac4
#if defined(__BORLANDC__)
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Bjorn Reese Guest
|
Posted: Fri May 05, 2006 9:21 am Post subject: Re: Identifying compiler |
|
|
Rune Allnor wrote:
| Quote: | - Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
http://predef.sourceforge.net/
--
mail1dotstofanetdotdk
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Roland Pibinger Guest
|
Posted: Fri May 05, 2006 9:21 am Post subject: Re: Identifying compiler |
|
|
On 3 May 2006 16:02:15 -0400, "Rune Allnor" <allnor (AT) tele (DOT) ntnu.no>
wrote:
| Quote: | I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
|
Yes, if you have to do it and if you do it as sparingly as possible
(once and only once).
| Quote: | - Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
http://predef.sourceforge.net/
Best wishes,
Roland Pibinger
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
kanze Guest
|
Posted: Sat May 06, 2006 2:21 pm Post subject: Re: Identifying compiler |
|
|
Rune Allnor wrote:
| Quote: | I am programming some C files that will be called from matlab.
According to the matlab documentation, a certain amount of
"voodoo" needs to be included if one uses one particular
compiler, to ensure some details to be handled correctly.
Now, I wonder how I can detect at compile time if this
compiler is used. If so, I might be able to make a header
like
#ifdef SomeCompiler
/* voodoo to be included */
#endif
- Is this a good way of doing things?
|
Not really. A better solution would be to make two separate
headers, in two different directories, and include one or the
other by means of a -I (or /I) option in the command line. It
it really is just one little tweak, this is a lot of extra work,
but my experience has been that even when it starts out as one
little tweak, it ends up affecting a lot of things, and you're
headers quickly become unreadable unless you use the separate
headers in separate directories solution (in which case, you end
up getting lost in a plethorie of small files -- but at least,
they're readable).
| Quote: | - Where can I find out what to substitute for "SomeCompiler"
above? The above must be valid for any Borland compiler.
|
You invoke the compiler. I've yet to find two compilers which
could be invoked by the same command line, so you already have a
means of choosing the invocation command line which depends on
the compiler (or more likely, on about a dozen different
factors: compiler, OS, architecture, debug or no, DLL or static
library...). Just define a name for each of your compilers, and
add a -D (or /D, or whatever) in your command line to define it.
(Note that this can be used with token pasting in an include
declaration to change the name of the included file.)
--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|