Re: programmatically determining if the machine is intel or not
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