在Mac和IPhone上分别运行下面的程序:
NSLog(@"char size = %lu", sizeof(char));
NSLog(@"short int size = %lu", sizeof(short));
NSLog(@"int size = %lu", sizeof(int));
NSLog(@"long int size = %lu", sizeof(long));
NSLog(@"long long int size = %lu", sizeof(long long));
NSLog(@"float size = %lu", sizeof(float));
NSLog(@"double size = %lu", sizeof(double));
NSLog(@"pointer size = %lu", sizeof(int *));
NSLog(@"BOOL size = %lu", sizeof(BOOL));
NSLog(@"NSInteger size = %lu", sizeof(NSInteger));
Mac(64位机器)上的输出为:
IPhone(64 为机器,不包括IPhone 5以及IPhone 5以下的机器,但是包括SE)上的输出为:
下面是IPhone中32位机器的输出(IPhone5及一下机器):
从输出上可以看到,64位机器的Mac和IPhone的数据长度一样,而32位的IPhone数据长度和64位机器大部分相同,不同之处为:
long类型在64位机器上是8字节,在32位机器上是4字节;
指针长度在64位机器上是8字节,在32位机器上是4字节;
NSInteger在64位机器上是8字节,在32位机器上是4字节