Jepessen
Jepessen

Reputation: 12415

`LL` vs `i64` suffix in C++ Visual Studio compiler

I'm trying to refactor an old C++ code. At some point I've something like:

#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
#  define I64_CONST(X)  X ## i64
#else
#  define I64_CONST(X)  X ## LL
#endif

So for defining a 64-bit literal in the code there's something like:

(uint32_t)((data_in >> 32) & I64_CONST(0x00000000ffffffff));

This is for using i64 suffix with Microsoft compilers and LL with other ones. Since I'm adapting it for C++17 and the minimum requirement that we have is to use Visual Studio 2019, is it possible to remove this and use LL everywhere, or is there some issue and it's better to maintain the distinction between compilers?

Upvotes: 3

Views: 643

Answers (1)

phuclv
phuclv

Reputation: 41814

Yes, long long is a new type since C++11 which contains at least 64 bits, so it can be used for your literals (unless the source code is using two's complement and the compiler is using one's complement/sign-magnitude then -263 won't fit)

Another way is to use the INT64_C in <cstdint> which was also introduced in C++11

#define I64_CONST INT64_C
auto v = INT64_C(0xFFFF0000FFFF0000);

See Purpose of using UINT64_C?

Upvotes: 7

Related Questions