Predefined macros for OSX PPC/Intel

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

  1. macrumors member

    Joined:
    May 29, 2006
    Location:
    Melbourne, Australia
    #1
    (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
     
  2. macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #2
    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. thread starter macrumors member

    Joined:
    May 29, 2006
    Location:
    Melbourne, Australia
    #3
    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
     
  4. macrumors regular

    rezwits

    Joined:
    Jul 10, 2007
    Location:
    Las Vegas
    #4
  5. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #5
    Go to developer.apple.com, then type "predefined macros" into the search box.
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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

    Krevnik

    Joined:
    Sep 8, 2003
    #7
    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