英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论