What is the Objective-C equivalent for 'long' in Java

Equivalent to 'long' in Java, what do we have in Objective-C, NSInteger?

+4
source share
3 answers

In Java, long always 64 bits. In C and Objective-C, a long may be 64 bits or it may be 32 bits or (in less common cases) it may be something completely different; standard C does not define the exact bit width.

In OS X a NSInteger is 64 bits on 64-bit platforms and 32 bits on 32-bit platforms. Mac 32-bit platforms are becoming less common, so you can use NSInteger and be fine.

However, if you always want to use a 64-bit integer, you probably want to use the int64_t data type defined in stdint.h .

+11
source

Java long is defined as a signed 64-bit value, neither long nor NSInteger guarantees this for Objective-C. For example, on 32-bit systems, plaforms, NSInteger, and long are 32-bit signed values. If your platform comes with C99 headers (for example, when your compiler is gcc-based), you should have stdint.h , which has platform-independent definitions for integer types with guaranteed sizes. The 64-bit subscription type is called int64_t .

+3
source
 #include <stdint.h> int64_t someVariable; // 64 bit signed integer, like Java long 

You did not ask, but int32_t is an analog of the Java int type (32-bit integer).

0
source

Source: https://habr.com/ru/post/1341899/


All Articles