There are different representation schemes for negative numbers,
for example these three (using 8bit examples).
- complement 2 : -n == ((0xff ^ n) +1)
- complement 1 : -n == ((0xff ^ n))
- signed magnitude: -n == ( 0x80 | n )
Equalities are different
complement 2 :
(-1 | -2)
== ((0xff ^ 1)+1) | ((0xff ^ 2)+1)
== (0xfe+1) | (0xfd+1)
== (0xff) | (0xfe)
== 0xff
== (0xfe +1)
== ((0xff ^ 1) +1)
== -1
== -( ((1+1) & (2+1)) -1 )
complement 1 :
(-1 | -2)
== (0xff ^ 1) | (0xff ^ 2)
== (0xfe) | (0xfd)
== (0xff)
== (0xff ^ 0x00)
== -0
== - ( 1 & 2 )
signed magnitude :
(-1 | -2)
== ( 0x80 | 1 ) | ( 0x80 | 2 )
== (0x81) | (0x82)
== (0x83)
== (0x80 | 3)
== -3
== -( 1 | 2 )
So that is what "implementation defined" means, depending on your compiler:
(-1 | -2) == -3 == -( 1 | 2 )
(-1 | -2) == -0 == -( 1 & 2 )
(-1 | -2) == -1 == -( ((1+1) & (2+1)) -1 )
"Considering values of these variables as negative,
just because the highest bit is 1,
is stupid, they are just bits!" you say?
Or maybe, "The values will never be so high, and definitly not semantically negative either."
Well, then do not use signed int for them.
That's what QAC wants to tell you.
If you do not happen to already know it,
I bet you will never guess which representation your compiler
(or at least most todays compilers for actual hardware-implemented ALUs) uses.