Unsigned long conflict with uint64_t?

We use specialized specialization for some type parameter

class my_template_class<uint64_t M>: public my_template_class_base<uint64_t> { .... } class my_template_class<unsigned long long,M>: public my_template_class_base<unsigned long long> { .... } 

This works fine with 64 bit compilation with gcc. When we try to use 32-bit mode, it reports the “previous definition” for the two classes.

So, unsigned long long matches uint64_t in 32-bit compilation, but not in 64-bit correlation?

The compilation difference is the CXX flag -m32 and -m64

+5
source share
2 answers

So, uint64_t unsigned long long match uint64_t in 32-bit compilation, but not in 64-bit compilation?

Yes.

In 32-bit mode, the most probable long is 32 bits, and long long is 64 bits. In 64-bit mode, both are probably 64 bits.

In 32-bit mode, the compiler (more precisely, the <stdint.h> header) defines uint64_t as unsigned long long , because unsigned long not wide enough.

In 64-bit mode, it defines uint64_t as unsigned long .

He could define it as unsigned long long in both modes. The choice is arbitrary; all that is required is that it must be a 64-bit type.

In general, each of the integer types defined in <stdint.h> is a typedef for some predefined type with corresponding characteristics. You cannot assume that any of them is different from the predefined types.

+12
source

This is from stdint.h for GCC 4.8:

 #if __WORDSIZE == 64 typedef unsigned long int uint64_t; #else __extension__ typedef unsigned long long int uint64_t; #endif 

So:

So the unsigned long long matches uint64_t in the 32-bit assignment, but not in the 64-bit assignment?

Yes.

+4
source

All Articles