PDA

View Full Version : Predefined macros for OSX PPC/Intel




AussieSusan
Jun 3, 2006, 07:22 PM
(Couldn't find this elsewhere - pointers please if I've missed something).

I'm trying to port some software from UNIX to my MAC and some of the header files contain a whole bunch of tests for various predefined macros to determine the environment and its capabilities (OS, big/little endian, processor type etc.)

What are the predefined macros that are available within GCC and XCode that can be used to differentiate OSX from other OS's, and Intel from PPC processors?

Thanks

Susan



GeeYouEye
Jun 3, 2006, 07:35 PM
Not sure, as most of the stuff I've coded isn't arch-specific, but I'm pretty sure you can find the answer in the Universal Binary Porting Guide.

AussieSusan
Jun 4, 2006, 02:03 AM
Thanks GeeYouEye - that started me on the right course.

Found the answer - cpp can tell you itself by typing:

cpp -dM
^D

at a terminal prompt. It will list out a whole lot of "#define..." statements.

Hope this helps someone else.

Cheers

Susan

rezwits
Dec 27, 2007, 08:25 AM
Yeah that kinda works except it's just "your own current machine running" specific. Be nice to have a list like this http://msdn2.microsoft.com/en-us/library/b0084kay(VS.80).aspx

Thanks

gnasher729
Dec 27, 2007, 09:34 AM
(Couldn't find this elsewhere - pointers please if I've missed something).

I'm trying to port some software from UNIX to my MAC and some of the header files contain a whole bunch of tests for various predefined macros to determine the environment and its capabilities (OS, big/little endian, processor type etc.)

What are the predefined macros that are available within GCC and XCode that can be used to differentiate OSX from other OS's, and Intel from PPC processors?

Thanks

Susan

Go to developer.apple.com, then type "predefined macros" into the search box.

kainjow
Dec 27, 2007, 11:33 AM
You shouldn't be concerned with whether your code is running on a PPC or Intel, but rather on a little vs big endian processor. Say the iPhone SDK comes out. You don't want a third if-else for ARM, you just need to detect its little endian processor.

Regarding detecting an OS, Mac OS X's GCC uses a __APPLE__ macro, and windows.h uses a WIN32 macro.

Krevnik
Dec 27, 2007, 02:16 PM
You shouldn't be concerned with whether your code is running on a PPC or Intel, but rather on a little vs big endian processor. Say the iPhone comes out. You don't want a third if-else for ARM, you just need to detect its little endian processor.

Regarding detecting an OS, Mac OS X's GCC uses a __APPLE__ macro, and windows.h uses a WIN32 macro.

In addition, the Universal Binary porting guide will likely mention this, but Apple provides macros for handling data from a specific endian format into the native format and back.

For /most/ purposes, this along with standard POSIX network byte-swapping APIs will probably get your most of the way past most of the arch differences between OS X PPC, and OS X Intel.