Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

`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 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, it’s possible to remove this and use LL everywhere, or there’s some issue and it’s better to maintain the distinction between compilers?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>

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

See Purpose of using UINT64_C?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading