Benefits of using nsinteger 1

Source: Internet
Author: User

The use of int and long is confusing today.

In C, the number of bytes of int and long is the same as that of the operating system pointer.

However, in C language, the length of long is always greater than or equal to int.

In objective-C, nsinteger is always recommended in Apple's official documentation.

What is the difference between it and Int? stackoverflow gives the answer.

In Apple's API implementation, nsinteger is an encapsulation that identifies the number of digits in the current operating system and automatically returns the maximum type.

The defined code is similar to the following:

# If _ lp64 _ | target_ OS _embedded | target_ OS _iphone | target_ OS _win32 | ns_build_32_like_64

Typedef long nsinteger;

Typedef unsigned long
Nsuinteger;

# Else

Typedef int nsinteger;

Typedef unsigned int
Nsuinteger;

# Endif

You usually want to use nsinteger when you don't know what kind of processor architecture your code might run on, so you may for some reason want the largest possible
Int type, which on 32 bit systems is just
Int, while on a 64-bit system it's a long.

When you don't know what type your operating system is, you usually want to use nsinteger, so maybe you want your int type range to be as large as possible, using nsinteger, in a 32-bit system, nsinteger is an int, that is, 32-bit. In a 64-bit system, nsinteger is 64-bit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.