正如標題所說,我想詢問iPhone上objective-c的基本數據類型。 那麼有沒有什麼好的文檔寫在這裏? 我需要表示變量的大小和變量的範圍。 所以在例子中: 短int - 2字節 - 有符號:-32768到32767和無符號:0到65535 這只是一個例子。 所以,如果有人知道一個網站只是在這裏寫它。 :)iPhone上的objective-c中的類型
135
A
回答
333
這是一個很好的概述:
http://reference.jumpingmonkey.org/programming_languages/objective-c/types.html
或運行該代碼:
32位過程:
NSLog(@"Primitive sizes:");
NSLog(@"The size of a char is: %d.", sizeof(char));
NSLog(@"The size of short is: %d.", sizeof(short));
NSLog(@"The size of int is: %d.", sizeof(int));
NSLog(@"The size of long is: %d.", sizeof(long));
NSLog(@"The size of long long is: %d.", sizeof(long long));
NSLog(@"The size of a unsigned char is: %d.", sizeof(unsigned char));
NSLog(@"The size of unsigned short is: %d.", sizeof(unsigned short));
NSLog(@"The size of unsigned int is: %d.", sizeof(unsigned int));
NSLog(@"The size of unsigned long is: %d.", sizeof(unsigned long));
NSLog(@"The size of unsigned long long is: %d.", sizeof(unsigned long long));
NSLog(@"The size of a float is: %d.", sizeof(float));
NSLog(@"The size of a double is %d.", sizeof(double));
NSLog(@"Ranges:");
NSLog(@"CHAR_MIN: %c", CHAR_MIN);
NSLog(@"CHAR_MAX: %c", CHAR_MAX);
NSLog(@"SHRT_MIN: %hi", SHRT_MIN); // signed short int
NSLog(@"SHRT_MAX: %hi", SHRT_MAX);
NSLog(@"INT_MIN: %i", INT_MIN);
NSLog(@"INT_MAX: %i", INT_MAX);
NSLog(@"LONG_MIN: %li", LONG_MIN); // signed long int
NSLog(@"LONG_MAX: %li", LONG_MAX);
NSLog(@"ULONG_MAX: %lu", ULONG_MAX); // unsigned long int
NSLog(@"LLONG_MIN: %lli", LLONG_MIN); // signed long long int
NSLog(@"LLONG_MAX: %lli", LLONG_MAX);
NSLog(@"ULLONG_MAX: %llu", ULLONG_MAX); // unsigned long long int
當在iPhone 3GS運行( iPod Touch和較老的iPhone應該會得到相同的結果):
Primitive sizes:
The size of a char is: 1.
The size of short is: 2.
The size of int is: 4.
The size of long is: 4.
The size of long long is: 8.
The size of a unsigned char is: 1.
The size of unsigned short is: 2.
The size of unsigned int is: 4.
The size of unsigned long is: 4.
The size of unsigned long long is: 8.
The size of a float is: 4.
The size of a double is 8.
Ranges:
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
INT_MIN: -2147483648
INT_MAX: 2147483647
LONG_MIN: -2147483648
LONG_MAX: 2147483647
ULONG_MAX: 4294967295
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807
ULLONG_MAX: 18446744073709551615
64位進程:
The size of a char is: 1.
The size of short is: 2.
The size of int is: 4.
The size of long is: 8.
The size of long long is: 8.
The size of a unsigned char is: 1.
The size of unsigned short is: 2.
The size of unsigned int is: 4.
The size of unsigned long is: 8.
The size of unsigned long long is: 8.
The size of a float is: 4.
The size of a double is 8.
Ranges:
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
INT_MIN: -2147483648
INT_MAX: 2147483647
LONG_MIN: -9223372036854775808
LONG_MAX: 9223372036854775807
ULONG_MAX: 18446744073709551615
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807
ULLONG_MAX: 18446744073709551615
20
請注意,還可以使用C99固定寬度類型非常清楚在Objective-C:
#import <stdint.h>
...
int32_t x; // guaranteed to be 32 bits on any platform
的wikipedia page有一個體面如果你沒有C標準的拷貝(你應該這樣做,因爲Objective-C只是C的一個微小的擴展)的描述。你也可以找到標題limits.h
和inttypes.h
是有用的。
+0
還有SInt32,UInt32等(在Core Audio中使用了很多)。 – 2014-04-14 11:02:34
12
更新爲新的64位拱
Ranges:
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
INT_MIN: -2147483648
INT_MAX: 2147483647
LONG_MIN: -9223372036854775808
LONG_MAX: 9223372036854775807
ULONG_MAX: 18446744073709551615
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807
ULLONG_MAX: 18446744073709551615
相關問題
- 1. 推薦類型讀的 - 的ObjectiveC
- 2. 的ObjectiveC,創建類的
- 3. GDATA-的ObjectiveC架構ARMv7的錯誤在YouTube上iPhone SDK的
- 4. iphone objectiveC alloc/release問題
- 5. 'java.lang.Class.getDeclaredField()'的ObjectiveC中的類似方法'
- 6. ObjectiveC中的MulticastDelegate
- 7. 中的ObjectiveC
- 8. iPhone ||上的請求類型Android的?
- 9. 獲取ObjectiveC中文件的內容類型
- 10. 從ObjectiveC類中引用UIViewController
- 11. 在ObjectiveC中測試類的加載
- 12. ObjectiveC中的循環#import/@類問題
- 13. 在iPhone上檢測802.11的類型
- 14. 綁定的ObjectiveC類的C#問題
- 15. iPhone中可用的不同類型的CATransition類型sdk
- 16. 使用iPhone中的C/C++靜態庫ObjectiveC Apps
- 17. iPhone上routeme上的地圖類型的地圖?
- 18. 在的ObjectiveC
- 19. 在的ObjectiveC
- 20. 在的ObjectiveC
- 21. 在的ObjectiveC
- 22. ObjectiveC中的靜態變量
- 23. 什麼是ObjectiveC中的retainCount?
- 24. MVC中的ObjectiveC編程
- 25. ObjectiveC中的計算交點
- 26. 優點和iOS中/的ObjectiveC
- 27. Sqlite3,在iphone中的Blob類型
- 28. 檢測iPhone中斷的類型
- 29. 如何知道Iphone上Objective C中變量的類型?
- 30. iPhone /的ObjectiveC-C浮子師不正確的輸出
注意跟iOS 7 SDK的發佈,一些類型是在64位模式做大。 – JeremyP 2013-09-30 16:43:09
更新爲64位進程 – jjxtra 2013-12-21 00:33:08
真棒回答真的很有幫助。有趣的是,在Swift中,你可以聲明一個「var」並將它留在那個哈哈:) – 2015-05-13 08:14:33