unsigned long long conflict with uint64_t?

unsigned long long conflict with uint64_t?

本文关键字:long with conflict unsigned uint64      更新时间:2023-10-16

我们对一些类型参数使用模板特化,比如

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> {
 ....
}

这是完美的64位编译与gcc。而当我们尝试32位模式时,它会报告以上两个类的"先前定义"。

所以unsigned long long在32位编译中与uint64_t相同,但在64位编译中却不同?

编译的区别是CXX标志-m32-m64

所以unsigned long long在32位编译中与uint64_t相同,但在64位编译中不一样?

是的。

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

在32位模式下,编译器(更准确地说是<stdint.h>头文件)将uint64_t定义为unsigned long long,因为unsigned long不够宽。

在64位模式下,将uint64_t定义为unsigned long

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

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

这是来自stdint.h的GCC 4.8:

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

:

所以unsigned long long在32位复杂度中与uint64_t相同,而不是在64位复杂度中?

是的。