What is the number 0ui64?

I see

 #define NUM_MAX_VOLUME 0ui64

      

in other people's code

What is the number 0ui64? It seems to be not a hexadecimal number.

+3


source to share


4 answers


I guess there are many answers, but no one has pointed out the official and authoritative documentation that should be noted in my opinion, so here's the MSDN documentation :

unsigned-suffix: one of

u U

and

64 bit integer suffix:

i64 LL ll

So, it really is not a hexadecimal number, but basically the macro defines zero, which is an unconfirmed 64-bit integer. Note that 0Ui64

, 0ULL

, 0ULL

etc. They will be the same too.



This is necessary if you want to make sure the sign and size are fixed so that it cannot be unexpected or undefined.

It is not standard C ++ or C, but the Microsoft compiler. Try to avoid this.

Since your question is tagged as Qt, it is recommended to use quint64 and Q_UINT64_C which will work cross-platform. So, you should write something like this:

#define NUM_MAX_VOLUME Q_UINT64_C(0)

      

+4


source


"ui64" means unsigned 64-bit integer. In some cases, this is a non-standard suffix. "0ui64" is just 0, and I think there is a reason to write it like it's compatibility.



+3


source


It is mainly used in an expression where the size of the operand matters (constant here). Take a shift, for example:

auto i = 1 << 36;

      

On a machine where int

is 32-bit length will result in undefined behavior . Because 1

here is taken as int

, and you try to move him by the size of the resulting type: int

. You want a 64 bit integral type, say unsigned long long

then you would do

auto i = 1ULL << 36;

      

This is not UB, since the resulting type would also be unsigned long long

due to the operand (now that too unsigned long long

).

Another example is C ++ 11 keyword type inference auto

. Try the following:

for (auto i = 0; i < v.size(); ++i)

      

With warnings enabled by 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)

      

display a warning. Again, as the suffix 0u

forced the compiler to infer the type i

as unsigned int

rather than just int

.

In your case, you have a suffix ui64

that is not standard C ++ , so it must be an implementation-specific extension that denotes an unsigned 64-bit integer.

+1


source


0xFull

for example is also a valid C ++ constant. This is 0xF, unsigned long long, aka ui64 in the transcription of Microsoft compilers.

0


source







All Articles