473,513 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to identify the platform & compiler while compiling?

Is there a way to find the platform and compiler name during compile
time so that conditional compilation can be performed in C? thanks.

Jan 27 '07 #1
6 2396
aki27 wrote:
Is there a way to find the platform and compiler name during compile
time so that conditional compilation can be performed in C? thanks.
There is no standard way to do what you're asking. Most compilers
define preprocessor constants, that identify the compiler, it's version
etc. Identifying the platform is bit more complex.

Why don't you look at tools like autoconf and autoheader that do this,
and much more, automatically for you? They're also available for many
platforms.

<http://sources.redhat.com/autobook/>

For further questions on this topic, consider a group like
comp.programming.

Jan 27 '07 #2
aki27 wrote:
>
Is there a way to find the platform and compiler name during compile
time so that conditional compilation can be performed in C? thanks.
The pre-existance of __STDC__ and possibly __STDC_VERSION__ will
tell you whether you have a system handling C90 or C99. This is
enough to handle all portable code. For other non-portable things
read your systems documentation. Those non-portable things are
off-topic on comp.lang.c.

--
Some informative links:
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)
<http://members.fortunecity.com/nnqweb/ (newusers)
Jan 27 '07 #3
On 27 Jan 2007 01:52:45 -0800, in comp.lang.c , "aki27"
<ak******@gmail.comwrote:
>Is there a way to find the platform and compiler name during compile
time so that conditional compilation can be performed in C? thanks.
Most compilers have a macro of some sort that assists with this. Look
at the headers of many portable gnu projects and you'll see 'em in
action.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jan 27 '07 #4
On Jan 27, 5:52 pm, "aki27" <akila...@gmail.comwrote:
Is there a way to find the platform and compiler name during compile
time so that conditional compilation can be performed in C? thanks.
There is a large list of predefined C/C++ compiler macros in http://
predef.sourceforge.net/

Jan 27 '07 #5

Thanks to all. My special thanks to Chih-Chung Chang. I found his
links usefull.

Jan 28 '07 #6
In article <11*********************@v45g2000cwv.googlegroups. com>
aki27 <ak******@gmail.comwrote:
>Is there a way to find the platform and compiler name during compile
time so that conditional compilation can be performed in C? thanks.
It is often (but not always) possible to do so. However, it is
often -- perhaps even usually -- unwise to do so.

In particular, people seem to like to do things like this:

#ifdef WIN32
some bizarre special-case code
#endif
#ifdef LINUX
some code
#endif
#ifdef HPUX
some code essentially identical to linux version
#endif
#ifdef BSD
third variant of code again essentially identical
#endif
#ifdef SOLARIS
fourth variant, with some extra goop for Solaris threads
#endif

What one *should* do, instead, is:

% cat win.c
... special windows-specific code ...
(no ifdefs at all here)

% cat everythingelse.c
... generic Unixy version of code ...
#ifdef USE_POSIX_THREADS
extra goop for POSIX threads
#endif
#ifdef USE_SOLARIS_THREADS
extra goop for Solaris threads
#endif
... more generic code ...

In other words, take the special (in this case, Windows-specific)
code and put it in a special file used only on the special system.
Take the common code and put it in a common file, which is used on
the common systems. If "#ifdef"s are needed -- which should be
made as rare as possible by separating out the "special" code --
make them conditional on the *feature* being exploited, not the
*system*. Here, although "Solaris threads" is the conditional, it
is the *feature*, not the system, that is being tested -- and note
that "Solaris threads" are not even present in sufficiently ancient
versions of Solaris. The code still works on those, even though
the platform and compiler are "Solaris"; you simply compile without
turning on "USE_SOLARIS_THREADS".

(You can of course set the default configuration based on the
platform and compiler. Just give the software engineer a clear
and obvious place to *change* those settings. If the default
for FooBlick systems turns out to be incorrect for the FooBlick
42, the place to adjust that will then be clear and obvious.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Jan 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
293
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
2
1075
by: Karthik | last post by:
I am developing a product , that I would like to compile in different development environments. So if I have to include any header file specific to VC++ 2003 implementation, I would like to put...
15
5301
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
1
2778
by: Runge Developer | last post by:
When compiling a VB.NET assembly we reguarly have the problem where it either hangs or produces the following error: ----- Visual Basic .NET compiler is unable to recover from the following error:...
4
5636
by: ARF | last post by:
I'm testing AutoCAD 2005 automation via VS2005 Pro C++/CLR and I'm getting fatal compiler errors. I start with a default C++/CLR class library project and modify it by adding the following...
12
2611
by: weaselboy1976 | last post by:
Hello, If we have c code like what's below, we will get an error because in the stringManipulator function we attempt to modify a string literal on the second call to the function. My question...
6
1560
by: Andrew Matthews | last post by:
Hi All, I have the following little class of iterators that allow me to iterate over elements in the file system. I have nested some of them, and then added Func<FileInfo, booldelegates to filter...
4
1962
by: gg9h0st | last post by:
i worte a simple code below. ------------------------------------------------------------------------------------ #include "stdafx.h" class Object { public: int a;
12
5429
by: Udhay | last post by:
I am new to vc++. Whether Visual Studio is a platform independent? Is there any chance of using my application created by vc in MAC or Linux. udhay
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7534
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.