473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 5885
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_PATCHLEVEL__ 0
#define __linux 1
#define __unix 1
#define __linux__ 1
#define __STDC_VERSION__ 199901L
#define __USER_LABEL_PREFIX__
#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_VERSION 102
#define __GNUC_MINOR__ 2
#define __STDC__ 1
#define __PTRDIFF_TYPE__ int
#define __tune_i386__ 1
#define __REGISTER_PREFIX__
#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**********************@freenews.iinet.net.au> ,
Sisyphus <ka**********@iinet.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.programming Non-language specific programming
news:comp.graphics.algorithms Issues of computer graphics

Compilers

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

Operating Systems

news:comp.os.msdos.programmer DOS, BIOS, Memory Models,
interrupts, screen handling,
hardware
news:comp.os.ms-windows.programmer.misc MS/Windows: Mice, DLLs, hardware
news:comp.os.ms-windows.programmer.win32 MS 32-bit API
news:comp.os.os2.programmer.misc OS/2 Programming
news:comp.sys.mac.programmer.misc Macintosh Programming
news:comp.unix.programmer General Unix: processes, pipes,
POSIX, curses, sockets
news:comp.unix.[vendor] Various Unix vendors
news:comp.os.linux.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**********************@freenews.iinet.net.au> ,
Sisyphus <ka**********@iinet.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
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
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...
11
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...
3
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...
1
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...
19
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...
12
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
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...
37
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.