Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the number 0ui64?

Tags:

c++

qt

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.

like image 812
Nyaruko Avatar asked Feb 11 '23 10:02

Nyaruko


2 Answers

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)
like image 114
lpapp Avatar answered Feb 14 '23 00:02

lpapp


"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.

like image 22
Lei Chen Avatar answered Feb 14 '23 00:02

Lei Chen