long
and long long
are built-in types defined by the core language.
int64_t
is defined by the <cstdint>
header (in practice include <stdint.h>
). It's defined as an alias for some built-in type. In your case it's defined as an alias for long
.
Built in types that can be the same size on some platform still need to be regarded as distinct types in order to not create ambiguous calls of overloaded functions.
There are even built in numerical types that guaranteed have the same size and signedness, but still are distinct. Namely, all three of unsigned char
, char
and signed char
are distinct and of size 1, but char
must be the same signedness as one of the others. Although I don't recommend doing it, technically you can freely overload functions based on just this difference.
Re
” Can I use long long
and int64_t
interchangeably on my machine, given that they are both integer types and have same size?
That depends on what you mean by “interchangeably”.
Since int64_t
with your compiler is an alias for long
, you can't call a function expecting an int64_t*
, with a long long*
pointer.
But long long
is guaranteed to be at least 64 bits, and in this sense it's only with respect to readability that it matters which of long long
and int64_t
you choose.