7 ms·
Does the type flow back from the return type to the negation operator? I had no idea C worked like that! I would have assumed -x was the same type as x and then
by chrisseaton 5y ago
Does the type flow back from the return type to the negation operator? I had no idea C worked like that! I would have assumed -x was the same type as x and then it was converted for the wider return type.
- skitter 5y agoI believe x gets promoted to int, negated and then narrowed to the return type.
- CalChris 5y agoThat is what the LLVM IR says happens: https://godbolt.org/z/4aexEK3aE https://godbolt.org/z/4aexEK3aE
- caf 5y agoArithmetic operations are never done in a type narrower than int. int8_t is necessarily narrower than int (int must be able to represent at least the range -32767..32767), so in -x the x is promoted to int, then negated.
- deleted 5y ago[deleted]