Predefined macros for OSX PPC/Intel

Discussion in 'Mac Programming' started by AussieSusan, Jun 3, 2006.

  1. macrumors member

    (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?


  2. macrumors 68000


    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.
  3. macrumors member

    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

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

    Hope this helps someone else.


  4. macrumors regular


  5. macrumors G5


    Go to, then type "predefined macros" into the search box.
  6. Moderator emeritus


    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.
  7. macrumors 68020


    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.

Share This Page