We use template specialization for some type parameter like
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 is working perfectly with 64-bit compilation with gcc. While when we try the 32 bit mode, it reports "previous definition" for above two classes.
So unsigned long long
is the same as uint64_t
in the 32-bit compilation but not in 64-bit compliation?
The compilation difference is the CXX
flag -m32
and -m64
So
unsigned long long
is the same asuint64_t
in the 32-bit compilation but not in 64-bit compilation?
Yes.
In 32-bit mode, most likely 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
isn't wide enough.
In 64-bit mode, it defines uint64_t
as unsigned long
.
It could have defined it as unsigned long long
in both modes. The choice is arbitrary; all that's required is that it has to be a 64-bit type.
In general, each of the integer types defined in <stdint.h>
is a typedef for some predefined type with the appropriate characteristics. You can't assume that any of them are distinct from the predefined types.
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 unsigned long long is the same as uint64_t in the 32bit compliation but not in 64 bit compliation?
Yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With