与uint64_t的unsigned long long冲突?

thu*_*ium 9 c++

我们对某些类型参数使用模板特化

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> {
 ....
}
Run Code Online (Sandbox Code Playgroud)

这与使用gcc的64位编译完美配合.当我们尝试32位模式时,它会报告上面两个类的"先前定义".

那么与32位编译unsigned long long相同,uint64_t但不是64位编译吗?

编译差异是CXX标志-m32-m64

Kei*_*son 17

这与32位编译中unsigned long long的相同,uint64_t但不是在64位编译中?

是.

在32位模式下,最有可能long是32位,long long是64位.在64位模式下,两者都可能是64位.

在32位模式下,编译器(更准确地说是<stdint.h>标题)定义uint64_tunsigned long long,因为unsigned long不够宽.

在64位模式下,它定义uint64_tunsigned long.

可以将它定义为unsigned long long两种模式.选择是任意的; 所需要的只是它必须是64位类型.

通常,定义的每个整数类型<stdint.h>都是具有适当特征的某些预定义类型的typedef.您不能假设它们中的任何一个与预定义类型不同.


Pao*_*o M 7

这是来自stdint.hGCC 4.8:

#if __WORDSIZE == 64
typedef unsigned long int   uint64_t;
#else
__extension__
typedef unsigned long long int  uint64_t;
#endif
Run Code Online (Sandbox Code Playgroud)

所以:

所以unsigned long long与32位compliation中的uint64_t相同,但不是64位compliation?

是.

  • 是的,对于海湾合作委员会。不要认为这在任何地方都是正确的。例如,Visual Studio 有一个无条件的“typedef unsigned long long uint64_t;” (2认同)