How to declare a long Objective-C? Is NSInteger compliant?

I see that NSInteger is used quite often, and the typedef for it on the iPhone is long, so technically I could use it when I expect an int (64) value. But should I be more explicit and use something like int64_t or long directly? What would be the disadvantage of using long ones?

+5
source share
5 answers

IIRC, longon the iPhone / ARM - 32 bits. If you want a guaranteed 64-bit integer, you should (really) use it int64_t.

+14
source

Integer Data Types Dimensions

  • short- ILP32: 2 bytes; LP64: 2 bytes

  • int- ILP32: 4 bytes; LP64: 4 bytes

  • long - ILP32: 4 ; LP64: 8

  • long long - ILP32: 8 ; LP64: 8

, :

__LP64__ 64- .

NSInteger typedef of long, 32- 32- 64- 64- .

64- int long NSInteger, .

: , LP64 Integer, ILP32 4 Integer , 4 .

32 64 64- Cocoa Touch.

:

Objective-C? NSInteger?

long, NSInteger, NSInteger .

- int64_t long ?

, 64- long, NSInteger, int64_t ( Wevah Said).

?

, , Apple .

+2

, , : int64_t.

, int NSInteger.

0

NSInteger , 32- 64- . 64 iPhone int 32 .

, iPhone NSInteger , , . โ€‹โ€‹ , . 32 32- 64- 64- .

NSInteger, , API Cocoa, NSInteger. , , stdint.h. , C

0

- , . , 32 64 , .

If you want to declare something as efficient as possible and large enough to count the elements, use NSInteger or NSUInteger. Note that both can be 32 or 64 bits and can be actually different types (int or long), depending on the compiler. This protects you from mixing types in some cases.

If you want 32 or 64 bits and nothing more, use int32_t, uint32_t, int64_t, uint64_t. Keep in mind that any type can be overly inefficient for some compilers.

0
source

All Articles