The difference between int and long

Source: Internet
Author: User
Tags windows x64

The data model determines the correspondence between the basic data type and the data width in C language. The 32-bit model we use is called ILP32, while 64-bit models have three kinds: LP64, LLP64, and ILP64. In a 64-bit model, the pointer must be 64-bit, but the width of int and long is defined differently in different data types. As the following table:

DataType LP32 ILP32 LLP64 LP64 ILP64
Char 8 8 8 8 8
Short 16 16 16 16 16
Int 16 32 32 32 64
Long 32 32 32 64 64
Long Long 64 64 64 64 64
Pointer 32 32 64 64 64

The former DOS is supposed to be LP32; now Windows 32 and Linux 32 are ILP32; in the upcoming 64bits world, the Windows x64 version uses the LLP64 model, LINUX64 uses the LP64 model, When you compile with GCC you can specify that-m32 be compiled according to the ILP32 model.

The pointer size is associated with the machine word length. For compatibility, when writing C code, declare a 32bit integer with int, and declare a 64bit integer with a long long.

According to POSIX, the correct format string for an integral type is:

Sign Char Short Int Long Long Long
Signed %hhd %hd %d %ld %lld
Unsigned %hhu %hu %u %lu %llu

The difference between int and long

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.