Equivalent to 'long' in Java what do we have in Objective C, NSInteger?
In Java, a long
is always 64 bits. In C and Objective-C, a long
might be 64 bits, or it might be 32 bits, or (in less common cases) it might be something else entirely; the C standard doesn't specify an exact bit width.
On OS X, an NSInteger
is 64 bits on 64-bit platforms, and 32 bits on 32-bit platforms. 32-bit Mac platforms are increasingly rare, so you can probably use NSInteger
and be fine.
However, if you always want a 64-bit integer, you'll probably want to use the int64_t
data type defined in stdint.h
.
A Java long is defined as a signed 64-bit value, neither long
nor NSInteger
guarantee 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), then you should have stdint.h
which has platform independent definitions for integer types with guaranteed sizes. The 64 bit signed type is named int64_t
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With