Home >Backend Development >C++ >Why Isn't 'long' 64 Bits on 64-bit Windows?

Why Isn't 'long' 64 Bits on 64-bit Windows?

DDD
DDDOriginal
2025-01-01 04:43:10953browse

Why Isn't 'long' 64 Bits on 64-bit Windows?

The Bit Size of 'long' in 64-bit Windows

The question arises: why is 'long' not 64 bits on 64-bit machines like Windows? This article delves into the history and implications of integer sizing on different platforms.

History of Integer Sizing

In the Unix world, two major integer size arrangements for 64-bit platforms emerged: ILP64 (int, long, pointers are 64-bit) and LP64 (long, pointers are 64-bit). ILP64 was abandoned in favor of LP64, which became the standard for modern 64-bit Unix systems like macOS X and Linux.

Microsoft's LLP64 Scheme

Microsoft employs LLP64 (long long, pointers are 64-bit) for 64-bit Windows, allowing recompilation of 32-bit software without changes. However, this differs from other 64-bit platforms and requires additional code adjustments to exploit 64-bit capabilities.

Platform-Neutral Integer Types

To approach integer sizing cross-platform, the C99 standard provides the header, offering platform-specific integer types: int8_t, int16_t, int32_t, int64_t, uintptr_t, intmax_t. Utilizing these types ensures that your application can adapt to different integer sizes.

Considerations for Windows

As Windows uses LLP64, it's crucial to note that 'long' remains 32 bits on 64-bit machines. This necessitates care when utilizing system types, which may deviate from platform-neutral integer types.

Conclusion

Understanding the nuances of integer sizing on different platforms is essential for developing cross-platform software. Utilizing platform-neutral integer types from and carefully handling system types can help ensure code portability and avoid potential integer size issues.

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

Statement:
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