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)
LP64 (Long, Pointers Are 64-bit)
LLP64 (Long Long, Pointers Are 64-bit)
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
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!