【问题标题】:Why can I not initialize a long long as expected?为什么我不能像预期的那样初始化 long long?
【发布时间】:2019-06-28 07:49:52
【问题描述】:

我的 VC2017 编译器显示此行为,有人可以解释一下这是怎么回事吗?:

long long testLLSigned0 = LLONG_MIN; // OK, equal to -922129006921510580
long long testLLSigned1 = -922129006921510580i64‬; // Error, invalid suffix i64 on integer constant
long long testLLSigned2 = -922337203685477580i64; // OK!
long long testLLSigned3 = -922337203685477580LL; // OK!
long long testLLSigned4 = -‭62129006921510911‬LL; // Error, use of undeclared identifier ‭62129006921510911‬LL
long long testLLSigned5 = -‭62129006921510911i64‬; // Error, use of undeclared identifier ‭62129006921510911i64

【问题讨论】:

  • Unicode 字符 'LEFT-TO-RIGHT OVERRIDE' (U+202D) 导致“数字”成为标识符。
  • 相关:stackoverflow.com/questions/45469214/… 文字 -922129006921510580 与值 -922129006921510580 不同。
  • @Eljay,感谢您的回答,从未听说过。我该如何解决这个问题?
  • @DrumM 更改编译器(可能)无济于事。您需要编辑文件并删除 unicode 控制字符。
  • 来自microsoft docs:[...]The i64 suffix is still supported but should be avoided because it is specific to Microsoft and is not portable.[...]

标签: c++ 64-bit long-long


【解决方案1】:

感谢EljayNathanOlivereerorikauser1810087,我解决了。

代码无法编译的最大原因是将计算值从 Windows 计算器 (!) 复制到任何现代编辑器 (!) 中。值 62129006921510911 被复制到编辑器中,带有 invisible unicode 字符!粘贴在 vim 中的结果显示:-<202d>62129006921510911<202c>LL

旁注:使用 LL 语法,i64 语法是 Microsoft 特有的,不可移植。

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-15
  • 1970-01-01
  • 1970-01-01
  • 2011-02-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多