I am new to C/C++, so I have a couple of questions about a basic type:
a) Can you explain to me the difference between int64_t and long (long int)? In my understanding, both are 64 bit integers. Is there any reason to choose one over the other?
b) I tried to look up the definition of int64_t on the web, without much success. Is there an authoritative source I need to consult for such questions?
c) For code using int64_t to compile, I am currently including <iostream>, which doesn't make much sense to me. Are there other includes that provide a declaration of int64_t?
In a 64-bit compile, int64_t is long int , not a long long int (obviously).
If long long is present, it must have at least 64 bits, so casting from (u)int64_t to (unsigned) long long is value-preserving. If you need a type with exactly 64 bits, use (u)int64_t , if you need at least 64 bits, (unsigned) long long is perfectly fine, as would be (u)int_least64_t .
It's defined in /usr/include/stdint.
The UInt64 value type represents unsigned integers with values ranging from 0 to 184,467,440,737,095,551,615. UInt64 provides methods to compare instances of this type, convert the value of an instance to its string representation, and convert the string representation of a number to an instance of this type.
a) Can you explain to me the difference between
int64_tandlong(long int)? In my understanding, both are 64 bit integers. Is there any reason to choose one over the other?
The former is a signed integer type with exactly 64 bits. The latter is a signed integer type with at least 32 bits.
b) I tried to look up the definition of
int64_ton the web, without much success. Is there an authoritative source I need to consult for such questions?
http://cppreference.com covers this here: http://en.cppreference.com/w/cpp/types/integer. The authoritative source, however, is the C++ standard (this particular bit can be found in §18.4 Integer types [cstdint]).
c) For code using
int64_tto compile, I am including<iostream>, which doesn't make much sense to me. Are there other includes that provide a declaration ofint64_t?
It is declared in <cstdint> or <cinttypes> (under namespace std), or in <stdint.h> or <inttypes.h> (in the global namespace).
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