View Full Version : Compiler definitions
kainsin
2002.06.21, 09:37 AM
I'm wondering if anyone knows a place where they list definitions that are used by the various Macintosh compilers so that code can be written to do different things depending on the compiler and such. I've looked around a bit ( not too hard since it wasn't a big deal ) but I've yet to spot a place where they list them nice and neat.
If not then maybe I'll start writing them down as I find them in various headers files and post a webpage myself or something.
Nimrod
2002.06.21, 11:24 AM
For CodeWarrior you want to put something like:
#if defined(__MWERKS__)
// codewarrior
#endif
And it would appear that the value if __MWERKS__ is a hex. representation of the version of CodeWarrior you're using.
I'd be interested to know the equivalents for GCC and MSVC.
kainsin
2002.06.21, 12:53 PM
I know these:
__MWERKS__ = CodeWarrior
__MPW__ = Apple's MPW
__APPLE__ = Project Builder ( but only project builder? )
It would still be cool if there was a complete list of all the definitions that the various compilers auto-defined so that we wouldn't have to go hounding through release notes and sample code in order to find out what they are.
OneSadCookie
2002.06.21, 05:28 PM
I use __APPLE_CC__ to check for PB's GCC. GCC defines __GNUC__ on all platforms, so you can check for that before using GCC extensions (like inline for C, __attribute__, typeof, &c).
I don't know how to check whether you're compiling on MacOSX or vanilla Darwin though.
This is what Apple's GCC 3.1 defines for compilation of C programs on my box (from gcc3 -v -E test.c):
__GNUC__=3
__GNUC_MINOR__=1
__GNUC_PATCHLEVEL__=0
__ppc__
__POWERPC__
__NATURAL_ALIGNMENT__
__MACH__
__BIG_ENDIAN__
__APPLE__
__NO_INLINE__
__STDC_HOSTED__=1
__APPLE_CC__=1041
__DYNAMIC__
__SIZE_TYPE__=long unsigned int
__PTRDIFF_TYPE__=int
__WCHAR_TYPE__=int
__WINT_TYPE__=unsigned int
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.