int 和integer的区别
来源:互联网 发布:迅游网游加速器mac版 编辑:程序博客网 时间:2024/04/27 20:45
查到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会根据系统的位数(32or64)自动选择int的最大数值(int or long)。
- int 和 Integer 的区别
- int 和 Integer 的区别
- int和Integer的区别
- int和Integer的区别
- int 和 integer的区别
- Integer和int的区别
- Integer 和 int 的区别
- int和integer的区别
- int和Integer的区别
- int 和integer的区别
- int 和 Integer的区别
- int 和integer的区别
- int 和integer的区别
- Integer和Int的区别
- int 和integer的区别
- int 和integer的区别
- Int 和integer的区别
- int 和Integer的区别
- HDU 2066 Floyd
- nodejs中supervisor设置
- hibernate 实现多表连接查询(转载)
- org.hibernate.InvalidMappingException:
- -bash: crontab: command not found
- int 和integer的区别
- linux 查看 tcp 某个IP链接数量
- oracle客户端连接两节点RAC集群的配置文件
- Archive 创建报错问题
- hibernate实现多表联合查询
- Python格式化中使用%运算符
- table 属性
- 比特币基础知识
- iOS "此证书由未知颁发机构签名"此问题的解决方法