GCC OS Specific Define List..

Programming, for all ages and all languages.
Post Reply
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

GCC OS Specific Define List..

Post by Brynet-Inc »

I've written applications and have ran into a few instances when using #ifdef's are very handy..

Here is a list of GCC define's that will help you too implement support for many OS's in a single codebase.

(The list..)
__FreeBSD__
__OpenBSD__
__NetBSD__
__bsdi__
__DARWIN__
__DragonFly__
__sun
__linux__
__CYGWIN__

Also, if you use MinGW..
__MINGW32__
__MINGW32_MAJOR_VERSION
__MINGW32_MINOR_VERSION

The host GCC defines the appropriate one automatically!, This means you can support multiple Operating systems without having to define OS specific flags like -DLINUX manually..

Example on how it works.. input.c
#include <stdio.h>

int main(void)
{
#ifdef __OpenBSD__
printf("Yay, Your using OpenBSD..\n");
#else
printf("Ah, Not running OpenBSD eh?..\n");
#endif
}

(just gcc -o output input.c)

I'm guessing a lot of the developers know of this already, But others may find this list fairly helpful as it can take awile trying to google them all ;). If you have any other handy GCC defines please post them here for reference :).
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:GCC OS Specific Define List..

Post by df »

99% of the time i need to differentiate between compilers rather than OSii.

_MSC_VER
__WATCOMC__
__GNUC__
__TINYC__
-- Stu --
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

I've recently found this, Contains all kinds of C define marco's..

Take a peek 8)

http://predef.sourceforge.net/index.php
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Post Reply