开发者

System Architecture

开发者 https://www.devze.com 2022-12-11 23:41 出处:网络
How do I determine whethe开发者_如何学Cr the currently running Mac OS X system is of 32bit or 64bit machine?It depends on what you mean by \"64 bit machine\". There are broadly three categories depend

How do I determine whethe开发者_如何学Cr the currently running Mac OS X system is of 32bit or 64bit machine?


It depends on what you mean by "64 bit machine". There are broadly three categories depending on processor family:

  1. Supports some 64-bit math operations
  2. Can run programs in X-64 mode (64-bit addressing)
  3. 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


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]; ...?

0

精彩评论

暂无评论...
验证码 换一张
取 消