4 ms·
these are signed, so you‘re getting -2^16... so many warnings to emit! /edit: had that mixed up in my head. Interestingly, clang does warn about the overflow:
by cfstras 7y ago
these are signed, so you‘re getting -2^16... so many warnings to emit!
/edit: had that mixed up in my head. Interestingly, clang does warn about the overflow:
main.c:6:17: warning: implicit conversion from 'int'
to 'int16_t' (aka 'short') changes value from
65536 to 0 [-Wconstant-conversion]
int16_t s16 = 65536;
- enedil 7y agoOops, you meant -2^15 I guess.
- NikkiA 7y agoNo, they meant -2^16, ie, -(0)
- majewsky 7y ago-2^16 is not -0. The unary minus binds more tightly than the binary xor, so this comes out as -2^16 = (-2) ^ 16 = 0b111...1110 ^ 0b10000 = 0b111...11011110 = -18 if I'm not mistaken.
- NikkiA 7y agoNo, we mean the power operator, 2 to the power of 16 would be '0' in a short int, since the value overflows... But since philosophically a signed int has '1's in every bit from the MSB to infinity towards the left, it should thus be -0 not 0.
- leereeves 7y agoIn two's complement (the usual binary representation of signed ints), -0 is the same as 0.