9

Now there is an iPhone coming with 64-bit architecture. long becomes 64 bits (while int remains 32-bit) , and everywhere NSInteger has been used is now a long and so 64-bits not 32. And twitter has quite a few people saying "I'm glad I've used NSInteger everywhere not int".

If you need to store a value that doesn't exceed 32 bits (for example in a loop which only loops 25 times), why should a long be used, because the 32 (at least) upper bits are going to be empty.

If the program has worked on 32-bit integers, then what benefit does using 64-bits for integers provide, when it uses up more memory?

Also there will be situations where using a 64-bit integer gives a different result to using a 32-bit integer. So if you use NSInteger then something may work on an iPhone 5S but not on an older device, whereas if int or long is explicitly used then the result will be the same on any device.

4

3 に答える 3

-1

__LP64__アプリが 32 ビットまたは 64 ビット エンジンで実行されている場合、Apple は下位互換性に注意を払い、マクロを使用して舞台裏で変数を適切なデータ型に変換します。

#if __LP64__ 
    typedef long NSInteger; 
    typedef unsigned long NSUInteger; 
#else 
    typedef int NSInteger; 
    typedef unsigned int NSUInteger; 
#endif 
于 2013-09-11T07:07:10.580 に答える
-1

NSInteger の内部ストレージは、さまざまなバッキング タイプの 1 つにすることができます。そのため、どこでも使用でき、心配する必要はありません。これが全体のポイントです。

于 2013-09-11T04:39:04.453 に答える