Description
The INT64
data type is a signed 64-bit integer. It is used to represent whole numbers that can range from approximately -9 quintillion to +9 quintillion. This type is fundamental for handling large numerical values, timestamps, or any data that requires a wide range of representation for integers.
Syntax
typedef __int64 INT64;
Details
In Windows programming, INT64
is an alias for the C/C++ built-in type __int64
. This type guarantees a minimum range of -263 to 263 - 1.
Platform Support
INT64
is supported across all modern Windows operating systems and architectures, including 32-bit and 64-bit environments.
Use Cases
- Storing large numerical quantities in databases or file formats.
- Representing time values, such as file timestamps or performance counters, which can exceed the range of a 32-bit integer.
- Performing calculations involving very large numbers where overflow with smaller integer types would occur.
- Interoperability with systems or libraries that define 64-bit integer types.
Example
The following C++ snippet demonstrates the declaration and usage of an INT64
variable:
#include <iostream>
#include <cstdint> // For INT64 definition in modern C++
int main() {
// Using the typedef from Windows headers, or C++20's std::int64_t
// If using older C++ or just Windows headers:
// typedef long long INT64; // In many compilers, long long is equivalent
// For clarity and cross-platform compatibility, std::int64_t is preferred in C++
std::int64_t largeNumber = 9223372036854775807LL; // Maximum value for signed 64-bit integer
std::int64_t negativeNumber = -123456789012345678LL;
std::cout << "A large positive number: " << largeNumber << std::endl;
std::cout << "A large negative number: " << negativeNumber << std::endl;
// Example of a calculation that might overflow a 32-bit integer
std::int64_t product = 3000000000LL * 3LL;
std::cout << "Product: " << product << std::endl;
return 0;
}
Related Information
<cstdint>
, which defines fixed-width integer types like std::int64_t
. This is generally the preferred and more portable way to declare 64-bit integers in modern C++ code, as it is guaranteed to be a signed 64-bit integer regardless of the compiler or platform. However, INT64
remains prevalent in older Windows API codebases.