Re: Detecting Intel / PowerPPC?
- From: Bill Stevenson <bstevenson@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 12 Mar 2006 23:12:50 -0500
On 2006-03-02 06:44:11 -0500, Michael Ash <mike@xxxxxxxxxxx> said:
Mike <no@xxxxxxxx> wrote:Hi,
Is there a system call (C++) which I can use to check whether the program is
executing on an Intel machine or a PowerPC?
A couple of files which my application loads from the hard disk contain floating
point numbers and then they need to be swapped (low / big endian) when they're
loaded if the user is on an Intel Mac.
Look at the routines in CFByteOrder.h. You can use those to load and conditionally swap values (ints or floats) without worrying about what processor you're on.
If you really want to roll your own (please don't), then you can use the __BIG_ENDIAN__ and __LITTLE_ENDIAN__ preprocessor defines.
Indeed, that's the good answer. The bad answer is
#include <stdio.h>
int main(void)
{
int x=1;
if ((int) (* (char *) &x))
printf("This is a little endian architecture\n");
else
printf("This is a big endian architecture\n");
}
But really, it's clever and fun. Go with what Michael said for good software!
-Bill
--
Bill Stevenson
Mac OS X Product Release Group
Apple Computer
bstevenson at remove this text dot apple dot com
.
- References:
- Detecting Intel / PowerPPC?
- From: Mike
- Re: Detecting Intel / PowerPPC?
- From: Michael Ash
- Detecting Intel / PowerPPC?
- Prev by Date: Re: Drawing a Bezier curve
- Next by Date: Unix static libs in OS X
- Previous by thread: Re: Detecting Intel / PowerPPC?
- Next by thread: Re: Detecting Intel / PowerPPC?
- Index(es):
Relevant Pages
|
Loading