c++ - uint64_t t3 = MAXDWORD + 1 == 0?

标签 c++

我真的不明白下面的代码发生了什么。为什么 t3 为零?

uint64_t t1 = MAXDWORD;         // t1 contains 4294967295 - CORRECT
uint64_t t2 = t1 + 1;           // t2 contains 4294967296 - CORRECT
uint64_t t3 = MAXDWORD + 1;     // t3 contains 0 (zero)   - HUH??

最佳答案

decltype(MAXDWORD) 是比 uint64_t 更窄的类型。所以表达式 MAXDWORD + 1 也不是 uint64_tunsigned 环绕行为在赋值之前被观察到到 t3

t1 + 1 使用 uint64_t 类型在 unsigned 算术中执行,该类型更宽。

关于c++ - uint64_t t3 = MAXDWORD + 1 == 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53152486/

相关文章:

c++ - STL 映射错误 : no template named 'map' in namespace 'std' ; did you mean 'max' ?

c++ - 从套接字读取一个字节与多个字节

c++ - 如何检查是否为 C++ 中的模板定义了特定运算符?

C++:Windows 10 x64 和 Windows 7 x64 上的 MFC 应用程序

c++ - 有没有办法在 C++ 的类之外调用基函数?

c++ - 如何在 C++ 中从全名字符串中分离和排列名字

c++ - 如何修复错误 C4930 : 'AMyStaticMeshActor a(void)' : prototyped function not called (was a variable definition intended?)

C++:在实例化类成员时使用 new 关键字与不使用关键字之间的区别?

c++ - 使用并行编程 C++ 计算/访问 vector

android - 为 Android 构建 SDL 混音器