Data type differences between 64-bit and 32-bit programming (C + +)

Source: Internet
Author: User

C + + simply defines the relationships between these basic data types, and does not define the word length that strictly defines them. On different platforms, depending on the compiler's implementation, their word lengths are shown in the following table:

Data type

LP64

ILP64

LLP64

ILP32

LP32

Char

8

8

8

8

8

Short

16

16

16

16

16

_int32

N/A

32

N/A

N/A

N/A

Int

32

64

32

32

16

Long

64

64

32

32

32

Long Long

N/A

N/A

64

N/A

N/A

Pointer

64

64

64

32

32

In this table, LP64,ILP64,LLP64 is a word length model on a 64-bit platform, and ILP32 and LP32 are word-length models on 32-bit platforms.

LP64 means long and pointer are 64 bits, ILP64 refers to Int,long,pointer is 64 bits, LLP refers to long long and pointer is 32-bit. ILP32 refers to Int,long and pointer are 32-bit, LP32 refers to long and pointer is 32 bits.

32-bit Windows is using the ILP32 data model, and 64-bit Windows is using the LLP64 data model.

So, the biggest difference between 32-bit programming on Windows and 64-bit programming (that is, the difference between IP32 and LLP64) is that the length of the pointer is different?? Changed from 32 bits to 64 bits.

Win32 API In many cases, you need to convert integers to pointers or vice versa. There is no problem with 32-bit hardware, where the size of the pointer is the same as the integer size, but it is completely different on 64-bit hardware.

For this reason, m$ has a so-called "polymorphic type":

For specific precision, you can use a fixed-precision data type. Regardless of the processor's word size, they are the same size. Most of these types include precision in their names, as can be seen in the following table:

type definition

DWORD32

32-bit unsigned integer

DWORD64

64-bit unsigned integer

INT32

32-bit signed integer

INT64

64-bit signed integer

LONG32

32-bit signed integer

LONG64

64-bit signed integer

UINT32

unsigned INT32

UINT64

unsigned INT64

ULONG32

unsigned LONG32

ULONG64

unsigned LONG64

Also, use the pointer precision data type when you want the precision of the data type to vary with the size of the processor word. These types are also known as polymorphic data types. These types usually end with a _ptr suffix, as shown in the following table:

Table 2. Data type for pointer precision
Type Defined

Dword_ptr

unsigned long type for pointer precision

Half_ptr

Half the size of the pointer. Used to contain a pointer and two small fields in the structure

Int_ptr

Signed integral type for pointer precision

Long_ptr

Signed long type of pointer precision

size_t

The maximum number of bytes that the pointer can reference. Used to count the entire range that must span the pointer

ssize_t

Signed size_t

Uhalf_ptr

unsigned half_ptr

Uint_ptr

Unsigned INT_PTR

Ulong_ptr

unsigned long_ptr

LPARAM

Synonyms with long_ptr, (defined in WTypes.h)

WPARAM

Synonyms with uint_ptr, (defined in WTypes.h)

All Win32 APIs that pass parameters or contextual information through integer parameters are changed to use these new types.

In addition, fixed-length pointers were also presented: Pointer_32 and pointer_64:

#define POINTER_32 __ptr32

#define POINTER_64 __ptr64

PS:M$DN is defined in the Basetsd.h, but is actually defined in WinNT.h.

http://blog.csdn.net/harbinzju/article/details/5785024

Data type differences between 64-bit and 32-bit programming (C + +)

Related Article

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.