Home > Backend Development > C++ > Is 'long' Really 64-bits on 64-bit Windows?

Is 'long' Really 64-bits on 64-bit Windows?

DDD
Release: 2025-01-01 04:50:10
Original
183 people have browsed it

Is 'long' Really 64-bits on 64-bit Windows?

Understanding the Bit Size of 'long' on 64-bit Windows

Question:

Conlicting information suggests that 'long' may not be 64 bits on 64-bit Windows machines. Is this true, and what should programmers use instead?

Answer:

The answer lies in examining different integer size arrangements on 64-bit platforms:

ILP64 (Int, Long, Pointers Are 64-bit)

  • All integer data types and pointers are 64 bits.

LP64 (Long, Pointers Are 64-bit)

  • Long and pointer types are 64 bits.
  • Int and other integer types remain 32 bits.

LLP64 (Long Long, Pointers Are 64-bit)

  • This is the scheme used by Microsoft in 64-bit Windows.
  • Long long and pointer types are 64 bits.
  • Int and long remain 32 bits.

Implications for Windows:

On 64-bit Windows, 'long' is indeed 32 bits, unlike on other 64-bit platforms. Microsoft adopted the LLP64 scheme to ensure compatibility with existing 32-bit applications.

Recommendations:

To ensure platform-neutral code, use integer types from the header:

  • int32_t for 32-bit integers
  • int64_t for 64-bit integers
  • uintptr_t for pointers

Be cautious when using system types (e.g., 'long') as they may vary across platforms. Only use intptr_t as the result of subtracting two uintptr_t values.

Conclusion:

The bit size of 'long' on 64-bit Windows is 32 bits, deviating from the LP64 scheme used by many other 64-bit systems. To avoid platform-specific complications, programmers should adopt platform-neutral integer types and carefully handle system types.

The above is the detailed content of Is 'long' Really 64-bits on 64-bit Windows?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template