Re: Detecting Intel / PowerPPC?
- From: Don Bruder <dakidd@xxxxxxxxx>
- Date: Tue, 14 Mar 2006 17:57:45 -0800
In article <WKANf.46723$d5.203491@xxxxxxxxxxxxxxx>,
"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)
{
unsigned int foo;
Byte *fooPrime;
int ReturnValue = 0; // Assume BigEndian until we find out otherwise
foo = 0xFF11EE22;
fooPrime = (Byte *)&foo;
if (*fooPrime == 0xFF)
{
// We're already set up to return BigEndian;
}
else
{
ReturnValue = 1; // Say it's a LittleEndian machine
}
return ReturnValue;
}
Call it at initialization, then behave accordingly when you get to the
point of loading your data. Granted, it's not exactly elegant, but I'd
expect it to tell you which way things get crammed into RAM.
Fair warning: Coded "seat of the pants", with no Intel-based Mac to test
on. Give it a whirl - If it works, great. If not, <shrug> I'll refund
what you paid for it. :)
--
Don Bruder - dakidd@xxxxxxxxx - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more info
.
- Follow-Ups:
- Re: Detecting Intel / PowerPPC?
- From: Michael Ash
- Re: Detecting Intel / PowerPPC?
- References:
- Detecting Intel / PowerPPC?
- From: Mike
- Detecting Intel / PowerPPC?
- Prev by Date: Re: Detecting Intel / PowerPPC?
- Next by Date: Re: Ho do I flush an NSView immediately?
- Previous by thread: Re: Detecting Intel / PowerPPC?
- Next by thread: Re: Detecting Intel / PowerPPC?
- Index(es):
Relevant Pages
|
Loading