Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Objective C equivalent for 'long' in Java

Tags:

objective-c

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

like image 745
Abhinav Avatar asked Dec 07 '22 23:12

Abhinav


2 Answers

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.

like image 105
mipadi Avatar answered Dec 21 '22 23:12

mipadi


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.

like image 36
Nordic Mainframe Avatar answered Dec 22 '22 00:12

Nordic Mainframe