473,761 Members | 8,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine OS and compiler

Hi,

Is there anything in the ANSI C standard covering the means by which I
can determine the operating system and compiler being used (at the
preprocess stage) ?

If so, then how might I determine (at the preprocess stage) whether the
operating system upon which the app is being built is Win32 or not, and
whether the compiler being used is gcc or not ?

If, on the other hand, this question is OT here, can someone provide me
with the name of a newsgroup where I could (legitimately) ask about
achieving such a determination.

Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.

Nov 14 '05 #1
3 5922
Sisyphus wrote:
Is there anything in the ANSI C standard covering the means
by which I can determine the operating system and compiler
being used (at the preprocess stage)?
No.
If so, then how might I determine (at the preprocess stage)
whether the operating system upon which the application is being built
is Win32 or not, and whether the compiler being used is gcc or not?

If, on the other hand, this question is OT here,
can someone provide me with the name of a newsgroup
where I could (legitimately) ask about achieving such a determination.
gnu.gcc.help

You can get gcc to print out
all of the predefined C preprocessor macros for you:
cat empty.c
gcc -std=c99 -E -dM empty.c

#define __HAVE_BUILTIN_ SETJMP__ 1
#define __unix__ 1
#define __i386__ 1
#define __SIZE_TYPE__ unsigned int
#define __ELF__ 1
#define __GNUC_PATCHLEV EL__ 0
#define __linux 1
#define __unix 1
#define __linux__ 1
#define __STDC_VERSION_ _ 199901L
#define __USER_LABEL_PR EFIX__
#define __STDC_HOSTED__ 1
#define __WCHAR_TYPE__ long int
#define __gnu_linux__ 1
#define __WINT_TYPE__ unsigned int
#define __GNUC__ 3
#define __STRICT_ANSI__ 1
#define __GXX_ABI_VERSI ON 102
#define __GNUC_MINOR__ 2
#define __STDC__ 1
#define __PTRDIFF_TYPE_ _ int
#define __tune_i386__ 1
#define __REGISTER_PREF IX__
#define __NO_INLINE__ 1
#define __i386 1
#define __VERSION__ "3.2 20020903 (Red Hat Linux 8.0 3.2-7)"

Nov 14 '05 #2
In article <40************ **********@free news.iinet.net. au>,
Sisyphus <ka**********@i inet.net.au> wrote:
Hi,

Is there anything in the ANSI C standard covering the means by which I
can determine the operating system and compiler being used (at the
preprocess stage) ?
Not specified in the standard, but there is a mechanism that the standard
allows and that most compilers use:
If so, then how might I determine (at the preprocess stage) whether the
operating system upon which the app is being built is Win32 or not, and
whether the compiler being used is gcc or not ?
Most compilers will define a preprocessor macro that identifies
the compiler and operating system. (There's nothing preventing an
implementation for the DeathStation from defining all such macros and
then blowing up your terminal when it sees code that uses extensions
specific to some other compiler, but with implementations that attempt
to provide a nonnegative QoI this is usually not a problem.)

The standard allows implementations to use most symbols beginning with "_"
(and all symbols beginning with "__") for any use the implementors can
come up with, so these macros typically look something like "__unix__"
or "_WIN32".

If, on the other hand, this question is OT here, can someone provide me
with the name of a newsgroup where I could (legitimately) ask about
achieving such a determination.


Given the information above, you'd be better off checking your compiler's
documentation to find what macro(s) it defines. If you can't find it
there, a newsgroup for your OS or compiler should be able to tell you.

Potentially helpful newsgroups, from the CLC welcome message:
--------
Languages and Programming

news:comp.lang. c++ The C++ Programming Language
news:comp.lang. asm.x86 x86 assembly language programming
news:comp.progr amming Non-language specific programming
news:comp.graph ics.algorithms Issues of computer graphics

Compilers

news:gnu.gcc The gcc free C compiler
news:comp.os.ms dos.djgpp x86 version of the free gcc C
compiler

Operating Systems

news:comp.os.ms dos.programmer DOS, BIOS, Memory Models,
interrupts, screen handling,
hardware
news:comp.os.ms-windows.program mer.misc MS/Windows: Mice, DLLs, hardware
news:comp.os.ms-windows.program mer.win32 MS 32-bit API
news:comp.os.os 2.programmer.mi sc OS/2 Programming
news:comp.sys.m ac.programmer.m isc Macintosh Programming
news:comp.unix. programmer General Unix: processes, pipes,
POSIX, curses, sockets
news:comp.unix.[vendor] Various Unix vendors
news:comp.os.li nux.development .apps Linux application programming
--------
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca
Start with your English classes; only when you've got the point that spelling
is not completely optional are you ready to proceed to the rather more exacting
discipline of programming. --Richard Bos in comp.lang.c
Nov 14 '05 #3
In article <40************ **********@free news.iinet.net. au>,
Sisyphus <ka**********@i inet.net.au> wrote:
Hi,

Is there anything in the ANSI C standard covering the means by which I
can determine the operating system and compiler being used (at the
preprocess stage) ?

If so, then how might I determine (at the preprocess stage) whether the
operating system upon which the app is being built is Win32 or not, and
whether the compiler being used is gcc or not ?
Why would you want to know whether the compiler runs on Windows or not?
For example, the Metrowerks CodeWarrior compilers will produce identical
code, whether you run them on a Macintosh or on Windows. What you want
to know is what platform you are compiling for.
If, on the other hand, this question is OT here, can someone provide me
with the name of a newsgroup where I could (legitimately) ask about
achieving such a determination.


Read the documentation of various compilers. Most compilers will have a
few predefined #define's that let you determine which compiler you are
using. Of course you cannot draw any conclusions for compilers that you
haven't seen yet, you can only hope that any compiler that is not a gcc
compiler won't have __GCC_COMPILER_ _ predefined (or whatever gcc uses to
identify itself).
Nov 14 '05 #4

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

Similar topics

27
6796
by: Kevin A | last post by:
Hi, Is there a way to determine the name and version of the operating system in a portable way? (for Solaris/Linux) Thanks, Kevin
1
1731
by: Ashabul Yeameen | last post by:
I am writing a program which at some point need to call fputwc() function. But since I want to make this code portable I've decided to write my own fputwc() funcion where the compiler doesn't supply this funcion. But how to determine whether the compiler supports wide character or not (depending on which my funcion will compile). Is there any preprocessor directive? thanks in advance -Yeameen
11
2760
by: S. I. Becker | last post by:
Is it possible to determine if a function has been overridden by an object, when I have a pointer to that object as it's base class (which is abstract)? The reason I want to do this is that I want to call this function if it has been overridden, and not if it hasn't, e.g class CBase { public: virtual long mightBeOverridden(int i) { return 0; } // not a pure virtual function, since sub-classes should not have to define it
3
7802
by: Michael Ekstrand | last post by:
I'm looking for a standard (or standard-ish) way to determine the maximum value representable by a size_t. I can't seem to find anything officially standard - cstddef doesn't seem to define such a thing, nor does climits. Applying grep to my /usr/include reveals an stdint.h header which defines a SIZE_MAX, some further research indicates that this is a C99 standard header but not standard for either C89 or standard C++. My primary...
1
1549
by: redjoy | last post by:
I have a Visual Studio 2003 solution with multiple projects (3 C++, 2 C#, and 2 VB). The code has been maintained and upgraded since VC 6.0 by several developers. There are litarally several hundred files in the solution (the majority in the C++ projects.) I want to find out what files are REALLY used by the C++ projects. I know that the project file has a list of all files included in the specific project but I also know that I do not need...
19
6931
by: perry.yuan | last post by:
How could I determine the endianness of my compile environment at compile time, instead of run time? I need a macro ("some_expression"), i.e. #if some_expression #define TARGET_IS_LITTLE_ENDIAN #else #define TARGET_IS_BIG_ENDIAN No way or some way? TIA.
12
2581
by: Pablo Suarez | last post by:
When I code #include "myheader.h" then this header file is searched in the current directory. But where does the compiler search the header file when I write #include <myheader.h>
6
5819
by: wink | last post by:
I'd like to determine if a method has been overridden as was asked here: http://www.velocityreviews.com/forums/t564224-determining-whether-a-derived-class-overrides-a-virtual-memberfunction.html The answer was can't do it, but I thought I'd ask here, my test code is: #include <iostream>
37
2410
by: C_guy | last post by:
Does anyone know of a (hopefully free) tool that can traverse a project and determine which "#include"s are not needed or needed in every .C file? This would be helpful in removing header inclusions that are redundant and/or unnecessary. Thanks!
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3866
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 we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.