Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documentation concerning platform-specific macros in Linux/POSIX

When compiling a C/C++ program under Windows using Visual Studio (or a compiler that tries to be compatible) there is a predefined macro _WIN32 (Source: http://msdn.microsoft.com/en-us/library/b0084kay.aspx) that you can use for platform-specific #ifdef-s.

What I am looking for is an analogon under Linux: a macro which tells me that I am compiling for Linux/an OS that claims to be (more or less) POSIX-compatible.

So I looked into gcc documentation and found this: http://gcc.gnu.org/onlinedocs/cpp/System_002dspecific-Predefined-Macros.html

Applied to my program, the following macros (gcc 4.4.5 - Ubuntu 10.10) looked promising (I hope that I didn't drop an important macro):

#define __USE_BSD 1
#define __unix__ 1
#define __linux 1
#define __unix 1
#define __linux__ 1
#define _POSIX_SOURCE 1
#define __STDC_HOSTED__ 1
#define __STDC_IEC_559__ 1
#define __gnu_linux__ 1
#define __USE_SVID 1
#define __USE_XOPEN2K 1
#define __USE_POSIX199506 1
#define _G_USING_THUNKS 1
#define __USE_XOPEN2K8 1
#define _BSD_SOURCE 1
#define unix 1
#define linux 1
#define __USE_POSIX 1
#define __USE_POSIX199309 1
#define __SSP__ 1
#define _SVID_SOURCE 1
#define _G_HAVE_SYS_CDEFS 1
#define __USE_POSIX_IMPLICITLY 1

Where do I find a detailed documentation of them - as to the mentioned Windows-specific macros above?

Additionally I'd be interested in macros normally defined for other POSIX-compliant operating systems as *BSD etc.

like image 692
Nubok Avatar asked Dec 09 '22 11:12

Nubok


1 Answers

The glibc manual lists several of these macros, including _POSIX_SOURCE. However, they work differently from what you might expect: the programmer defines these macros (in a build script, probably) and the C library headers check it to enable or disable certain functionality.

like image 91
Fred Foo Avatar answered Jan 22 '23 18:01

Fred Foo