• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: programmatically determining if the machine is intel or not
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programmatically determining if the machine is intel or not


  • Subject: Re: programmatically determining if the machine is intel or not
  • From: Omar Qazi <email@hidden>
  • Date: Sat, 20 May 2006 00:40:38 -0700


On May 17, 2006, at 4:53 AM, Jonathan Sand wrote:

Does anyone know of a way to programmatically determine whether ones Mac code is running on PowerPC or Intel hardware?

You could use a simple C++ Function that exploits differences in the Architectures intentionally. I have written a quick function that exploits the endianess to give you the processor type:


//Function will return 1 if Big Endian,
//2 if Little Endian
//Or 0 if something weird happens
//(Power PC uses big, Intel uses little so 1 == PPC 2 ==x86)
int GetArch()
{
    int anInt = 0x33221101; //Create a four byte integer
    char *anIntAdr;
    char enByte;

    anIntAdr = (char *)&anInt;
    enByte = *anIntAdr;

    if (enByte == 0x33)
    {
        return 1;
    }
    else if (enByte == 0x01)
    {
        return 2;
    }
    else
    {
        return 0;
    }
}

int main(int argc,const char * argv[])
{
    if (GetArch() == 1)
    {
        printf("Power PC\n");
    }
    else if (GetArch() == 2)
    {
        printf("Intel\n");
    }
    else
    {
        printf("What the....\n");
    }
    return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: programmatically determining if the machine is intel or not
      • From: "Lee Falin" <email@hidden>
References: 
 >programmatically determining if the machine is intel or not (From: Jonathan Sand <email@hidden>)

  • Prev by Date: Re: NSAppleScript not in the main thread
  • Next by Date: Re: Bindings, CoreData, NSOutlineView, and NSTreeController
  • Previous by thread: Re: programmatically determining if the machine is intel or not
  • Next by thread: Re: programmatically determining if the machine is intel or not
  • Index(es):
    • Date
    • Thread