positive values ​instead negative values of integer_literals

93 Views Asked by At

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

There are 1 best solutions below

2
user17732522 On

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.