I see the
#define NUM_MAX_VOLUME 0ui64
in other people's code
What is the number 0ui64? It seems it is not a hex number though.
I am surpsised that there are many answers, but none has pointed out the official and authoritative documentation that should be noted in my opinion, so here goes the MSDN documentation:
unsigned-suffix: one of
u U
and
64-bit integer-suffix:
i64 LL ll
So, it is indeed not a hexa number, but basically a macro define to zero that represents an unsiged 64 bit integer number. Please note that 0Ui64
, 0ULL
, 0ull
, etc, would be all the same, too.
This is necessary when you want to make sure that the sign and size are fixed so that it cannot go unexpected or undefined behavior.
This is neither standard C++, nor C, but a Microsoft compiler feature. Try to avoid it.
Since your question is tagged as Qt, the recommendation is to use quint64 and Q_UINT64_C instead which will work cross-platform. So, you would write something like this:
#define NUM_MAX_VOLUME Q_UINT64_C(0)
"ui64" means unsigned 64-bit integer. It is a non-standard suffix in some cases. "0ui64" is just 0, and i guess the reason to write like this is for compatibility.
It's basically used in a expression where the size of the operand (the constant here) matters. Take shifting for example:
auto i = 1 << 36;
On a machine where int
is 32-bits long this will lead to undefined behaviour. Since the 1
here is taken as an int
, and you're trying to shift it beyond the size of the resulting type: int
. What you want is a 64-bit integral type, say unsigned long long
then you'd do
auto i = 1ULL << 36;
This isn't UB since the resulting type would also be an unsigned long long
due to the operand (which is now an unsigned long long
too).
Another example is type deduction of the C++11's auto
keyword. Try this:
for (auto i = 0; i < v.size(); ++i)
With warnings enabled GCC barks (live example)
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
However, changing this to
for (auto i = 0u; i < v.size(); ++i)
make the warning disappear. Again since the suffix 0u
led the compiler to deduce the type of i
as unsigned int
and not simply int
.
In your case, you've the suffix ui64
which isn't standard C++, so it should be an implementation-specific extension that denotes unsigned 64-bit integer.
0xFull
,for example, is also valid C++ constant. It is 0xF, unsigned long long, a.k.a. ui64 in Microsoft compilers transcription.