Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing for Compiler 1

Status
Not open for further replies.

Toyman

Programmer
Jun 19, 2001
68
0
0
GB
Hi

Is there a way to test which compiler compiled the source.

e.g

#if __mswin
blah blah windows compiled
#elseif __unix
blah blah unix compiled
#elseif (whatever other os compilers available)
#endif

I'm trying to write programs that will run on MS Windows and Red Hat (Server type Programs)

Some of the inlcude files are specifiec to Windows and other to Linux and others are common to both.

I would not like to develop two seperate programs.

Thanks
Carel
 
Is there a way to test which compiler compiled the source.
Compiled or is compiling?

If you really meant "compiled," then you often can, but by then you can't do much about it.

If you actually meant the second, then compilers usually define macros that can be used to cause conditional compilation of pieces of code. That works just like in your example.


Some macros to test for:

[tt]WIN32
_MSC_VER
__BORLANDC__
__MWERKS__
__TURBOC__[/tt]

For more info, grab a project that's already done this.

I'd suggest looking at the configuration header file used in Boost ( It should give you a good idea of what macros you need to test for, and also give you an example of a good design for using the macros in your own project.

Another piece of software that uses this approach is Zlib (
 
Thanks

yeah sorry, it should be compiling

Will have a look at the links !!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top