如何在OS X中使用標準C庫或Cocoa獲取CPU體系結構字符串?在OS X中獲取CPU arch字符串(C,Cocoa)
2
A
回答
2
2
這裏有一個作弊的方式排序:
#if defined(__i386__)
return "i386";
#elif defined(__x86_64__)
return "x86-64";
#elif defined(__arm__)
return "arm";
// etc...
#else
# error "Unknown architecture!"
#endif
這不是絕對必要的檢查在運行時,因爲有一個爲每個架構一個單獨的可執行映像。
0
從man 2 uname
:
#include <sys/utsname.h>
int uname(struct utsname *buf);
uname() returns system information in the structure pointed to by buf.
The utsname struct is defined in
<sys/utsname.h>:
struct utsname {
char sysname[]; /* Operating system name (e.g., "Linux") */
char nodename[]; /* Name within "some implementation-defined
network" */
char release[]; /* OS release (e.g., "2.6.28") */
char version[]; /* OS version */
char machine[]; /* Hardware identifier */
};
The length of the arrays in a struct utsname is unspecified;
the fields are terminated by a null byte ('\0').
提示: uname -m輸出返回(struct utsname).machine
。
相關問題
- 1. OS X獲取字符串
- 2. cocoa objective-c for os x:從路徑獲取卷裝入點
- 3. 從C獲取Mac OS X上的CPU數量?
- 4. 在c/cocoa中讀取和輸出UTF-8字符串
- 5. 在OS X Cocoa中的java.awt.Robot等價物?
- 6. 在C#中獲取子字符串?
- 7. 如何在OS X上獲取CPU溫度和風扇速度?
- 8. NSWindow vs ViewController - OS X - Cocoa
- 9. Mono for OS X和Cocoa
- 10. 字符串模塊出錯,python os x
- 11. OS X Cocoa - 將虛擬掃描代碼轉換爲Char字符
- 12. 從字符串中獲取X字符與PHP繞回
- 13. 在字符串中獲取字符數
- 14. 凍結Cocoa中的OS X屏幕
- 15. Objective-C串行 - Mac OS X
- 16. 獲取C++中字符串的長度
- 17. OS X PDF:獲取字體信息
- 18. 從字符串數組中獲取第一個字符串c
- 19. 獲取字符串前/ String.indexof在C#後
- 20. 獲取C中字符串的尾部
- 21. C獲取字符串中的字符串的一部分
- 22. Java字符串:如何獲取X,Y從一個字符串 「VT X,Y,Z」
- 23. 獲取字符串之間的字符串在C#
- 24. 在C#中解碼字符串時獲取未知字符
- 25. 從塊管理C字符串,NSAlert,OS X
- 26. 從字符串獲取子串C
- 27. 提取字符串,字符串X和字符串之間ÿ
- 28. 在Mac OS X上從可可中的NSImage獲取CGIImageRef
- 29. 如何從testmethod獲取c#中字符串的值在C#中
- 30. Cocoa-Touch字符串拆分
我不知道C很好,但我會運行'uname -m'並獲取輸出。 – Blender 2011-12-21 19:04:52