如何输入int64_t / uint64_t常量? [英] How to input int64_t / uint64_t constants?
本文介绍了如何输入int64_t / uint64_t常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么下面的最小(?)示例不能编译?
#包括< stdint.h>
// test.cpp:4:33:error:expected数字常量之前的初始表达式
// test.cpp:4:33:error:expected')'数字常量之前
const uint64_t test =(uint64_t 1)<< 30;
// const uint64_t test1 =(uint64_t(1))<< 30; //这个神奇的编译!为什么?
int main(){return 0; }
解决方案 不是有效的语法。在投射时,您可以使用
uint64_t(1)
或(uint64_t)1
。注释掉的例子的工作原理是,它遵循适当的强制转换语法,如下所示: const uint64_t test =((uint64_t)1 )<< 30;
What I'm trying to do is to define a constant equal to 2^30 (I may change it to something like 2^34, so I prefer to have a room larger than 32 bits for it).
Why the following minimal(?) example doesn't compile?
#include <stdint.h>
// test.cpp:4:33: error: expected primary-expression before numeric constant
// test.cpp:4:33: error: expected ')' before numeric constant
const uint64_t test = (uint64_t 1) << 30;
//const uint64_t test1 = (uint64_t(1)) << 30;// this one magically compiles! why?
int main() { return 0; }
解决方案
(uint64_t 1)
is not valid syntax. When casting, you can either use uint64_t(1)
or (uint64_t) 1
. The commented out example works because it follows the proper syntax for casting, as would:
const uint64_t test = ((uint64_t)1) << 30;
这篇关于如何输入int64_t / uint64_t常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文