What is Objective C equivalent for 'long' in Java
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
.
#include <stdint.h>
int64_t someVariable; // 64 bit signed integer, like Java's long
You didn't ask, but int32_t
is the analogue to Java's int
type (a 32-bit integer).
精彩评论