How do I determine whether the currently running Mac OS X system is of 32bit or 64bit machine?
I'm fairly certain that sizeof(long) == 4
on 32-bit systems and sizeof(long) == 8
on 64-bit systems. The same should be true of pointers.
a little greppy, but ..
#!/bin/sh
ioreg -l -p IODeviceTree | grep EFI64
if [ $? = 0 ]
then
echo "I am a 64bit machine!"
else
echo "I am a 32bit machine!"
fi
wrapped in an NSTask *task = [[NSTask alloc] init]; ...
?
It depends on what you mean by "64 bit machine". There are broadly three categories depending on processor family:
- Supports some 64-bit math operations
- Can run programs in X-64 mode (64-bit addressing)
- Has 64-bit kernel support
I assume that you mean sense "2" here, since that's the most relevant for application code. You don't have to worry about sense "1" unless you need to run on older PowerPC Macs, I believe.
You specifically mentioned doing this in C code, which doesn't actually make much sense. If you're compiling C code, you can just build your application "fat", with 32- and 64- bit variants, and therefore do the check at compile-time with:
#if _LP64
//64-bit stuff
#else
//32-bit stuff
#endif