2011-08-01 37 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"); 
}