Maybe performance? I feel that using non-fixed integers just makes programs more complicated and prone to fail when porting to another architecture.
In Java, the type long is 64-bit signed integer type. The type long is used where the type int is not that large to hold the desired value. The range of long is –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 which is quite large, to hold the larger values like big whole numbers.
An int is a 32-bit integer; a long is a 64-bit integer. Which one to use depends on how large the numbers are that you expect to work with. int and long are primitive types, while Integer and Long are objects.
Compiler designers tend to to maximize the performance of int arithmetic, making it the natural size for the underlying processor or OS, and setting up the other types accordingly. But the use of long int , since int can be omitted, it's just the same as long by definition.
Using short can conserve memory if it is narrower than int , which can be important when using a large array. Your program will use more memory in a 32-bit int system compared to a 16-bit int system.
std::intN_t
are provided only if the implementation can directly support them. So porting code that uses them can fail.
I would prefer std::intfastN_t
for general use because they have less restrictions and should be as fast or faster as int
.
Also, most C++ code uses int
everywhere so you might run into promotion weirdness when passing a std::int32_t
into a function accepting an int
, especially if sizeof(int)
is only 16 bits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With