int和NSInteger区别
来源:互联网 发布:新手开淘宝 编辑:程序博客网 时间:2024/04/29 16:15
今天在困惑int和long的使用。
查到c语言中,int和long的字节数是和操作系统指针所占位数相等。
但c语言中说,long的长度永远大于或等于int
objective-c里,苹果的官方文档中总是推荐用NSInteger
它和int有什么区别呢,stackoverflow这帮大神给了答案。
原来在苹果的api实现中,NSInteger是一个封装,它会识别当前操作系统的位数,自动返回最大的类型。
定义的代码类似于下:
#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
You usually want to use NSInteger when you don't know what kind of processor architecture your code might run on, so you may for some reason want the largest possible int type, which on 32 bit systems is just an int, while on a 64-bit system it's a long.
当你不知道你的操作系统是什么类型的时候,你通常会想要使用NSInteger,所以或许你想要你的int类型范围尽可能的大,用NSInteger,32位系统NSInteger是一个int,即32位,但当时64位系统时,NSInteger便是64位的。
- int和NSInteger区别
- NSInteger 和 int 区别
- int和NSInteger区别
- NSInteger 和int区别
- int和NSInteger区别
- NSInteger 和 int 区别
- int和NSInteger区别
- NSInteger和int的区别
- NSInteger和NSUInteger,int区别
- int和NSInteger的区别
- 【ios】int 和 NSInteger区别
- NSInteger 与 NSUInteger 和 int与 NSInteger 区别
- NSInteger 与 NSUInteger 和 int与 NSInteger 区别
- NSInteger 与 NSUInteger 和 int与 NSInteger 区别
- int和NSInteger和long区别
- NSInteger和int的区别与使用方法
- iOS int和NSInteger的区别
- NSInteger 与 NSUInteger 和 int 区别
- log event entry exceeded max_allowed_packet
- LIst的使用
- OVS 响应 OFPT_SET_CONFIG 过程分析
- 计算机系统-计算机硬件及系统发展史
- Matlab求方差,均值,均方差,协方差的函数
- int和NSInteger区别
- poj 2442 堆的应用(m组数取前n小)
- Android下实现静默安装指定APK
- test for this new blog~
- 软件顾问可视设计的得力助手——PowerMockup
- 【HDU】2458 Kindergarten 二分匹配
- UVA10651- Pebble Solitaire(位运算+记忆化搜索)
- hdu 2870
- Android之Goldfish