Assigning a 64-bit constant as
int64_t foo = 0x1234LL;
is not portable, because long long
isn't necessarily int64_t
. This post Which initializer is appropriate for an int64_t? discusses use of INT64_C()
macro from <stdint.h>
, but isn't it also possible to use static_cast
as
int64_t foo = static_cast<int64_t>(0x1234);
?
Which one should I prefer and why, or do both of them work well?
I have searched on the internet and on SO, but did not find any place where the static_cast
option is explored. I have also done tests using sizeof()
to confirm that it works in the simple cases.