Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AussieSusan

macrumors member
Original poster
May 29, 2006
54
0
Melbourne, Australia
(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

macrumors 68000
Dec 9, 2001
1,669
10
State of Denial
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

macrumors member
Original poster
May 29, 2006
54
0
Melbourne, Australia
Answer to my own question

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
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
(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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors 601
Sep 8, 2003
4,100
1,309
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.