2011-08-01 40 views
1

有没有办法在MAC上运行时找到进程架构?运行时CPU架构

我使用32位的sizeof(int) == 4和64位的sizeof(int) == 8。有没有一种优雅的方式?

+0

的常量。你是否在任何地方发送数据? – 2011-08-01 18:36:30

+2

如果只定位OS X,我肯定它有一些功能可以在不依赖'sizeof'运算符的情况下进行查询(sizeof'是*编译时*常量,不是吗? - 在这种情况下,有更适合CPP的定义我怀疑) – 2011-08-01 18:36:49

+0

我假设您使用多个体系结构二进制文件? –

回答

0

使用@property(readonly) NSInteger executableArchitecture,我想知道,如果它的事项NSBundleMach-O Architecture

NSInteger architecture = [[NSRunningApplication currentApplication] executableArchitecture]; 
if(architecture == NSBundleExecutableArchitectureX86_64) { 
    NSLog(@"running on 64bits"); 
else if (architecture == NSBundleExecutableArchitectureI386) { 
    NSLog(@"running on 32bits"); 
} else { 
    NSLog(@"running somewhere else"); 
}