Re: Detecting Intel / PowerPPC?
- From: Michael Ash <mike@xxxxxxxxxxx>
- Date: Wed, 15 Mar 2006 04:04:59 -0600
Don Bruder <dakidd@xxxxxxxxx> wrote:
In article <WKANf.46723$d5.203491@xxxxxxxxxxxxxxx>,[snip]
"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.
No clue about any sort of system call or built-in that would do it, but
it seems to me one could check by doing something like this in "plain
vanilla" C (which should work just fine in C++):
// return 0 if machine is BigEndian, 1 if LittleEndian
// Caveat: Assumes ints are four bytes. Alter accordingly
// if that's not true for your project.
int CheckEndianness(void)
It's.... interesting.... to see how many bizarre and truly
rube-goldbergish solutions this question provokes. And not just here,
these things seem to pop up wherever the question is asked.
The aforementioned preprocessor defines are the right way to do it. If you
don't trust them (maybe because your code has to compile on MS-DOS 3.2 and
you're too lazy to set up your headers properly or something), there's no
reason to get any more complicated than the below:
int IsBigEndian(void) {
int chunk = 1;
return *(char *)&chunk;
}
--
Michael Ash
Rogue Amoeba Software
.
- Follow-Ups:
- Re: Detecting Intel / PowerPPC?
- From: Paul Russell
- Re: Detecting Intel / PowerPPC?
- References:
- Detecting Intel / PowerPPC?
- From: Mike
- Re: Detecting Intel / PowerPPC?
- From: Don Bruder
- Detecting Intel / PowerPPC?
- Prev by Date: Re: Ho do I flush an NSView immediately?
- Next by Date: Better way to append C char (non-unicode) to NSString?
- Previous by thread: Re: Detecting Intel / PowerPPC?
- Next by thread: Re: Detecting Intel / PowerPPC?
- Index(es):
Relevant Pages
|
Loading