正整数值而不是整数文字的负值

huangapple go评论69阅读模式
英文:

positive values ​instead negative values of integer_literals

问题

在源代码中,我有一个负整数字面值。当我通过libclang解析源代码时,整数_literal函数clang_Cursor_Evaluate和clang_EvalResult_getAsInt返回一个正值。

例如,我在源代码中有int a = -555。如果你获取这个整数值并调用clang_Cursor_Evaluate和clang_EvalResult_getAsInt函数,后者将简单地返回555。为什么会发生这种情况?

英文:

In the source code, I have a negative int literal. When I parse the source code through libclang, the integer_leteral functions clang_Cursor_Evaluate and clang_EvalResult_getAsInt return a positive value for this.

For example, I had int a = -555 in the source code. If you get this integer_value and call the clang_Cursor_Evaluate and clang_EvalResult_getAsInt functions for it, the latter will simply return 555. Why is this happening?

答案1

得分: 4

在C和C++中,没有负整数文字。当你有类似-555的情况时,那是一个整数文字555和一个一元减号运算符。十进制整数具有带符号的整数类型,不会升级,因此它将得到预期的类型和值。

英文:

There are no negative integer literals in C and C++. When you have something like -555 that's an integer literal 555 and a unary minus operator. A decimal integer has a signed integral type that won't be promoted, so that works out to the expected type and value.

huangapple
  • 本文由 发表于 2023年3月7日 04:50:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定