I have been looking for an answert to the following behavior when working with Arduino. But have not found anything, therefore I hope you will be able to support.
I define two int8_t variables vA and vB. vA is defined as e.g. 125 an vB as 31. If I first add them and assign to a int8_t variable vSum, then call Serial.println(vSum) the number -100 is printed as expected (since they overflow as 8 bit numbers).
Now, when i call Serial.println(vA+vB) the result is wrong (156). As far as I understand the Serial.println() would in this case cast the result of the sum to a signed int. I would have expected, though, that it still returns the correct answer.
My understanding is obviously wrong. Does anybody know why it behaves like this?
Here once again the code
int8_t vA =125;
int8_t vB =31;
int8_t temp;
temp = vA+vB;
Serial.println(temp); // This works as expected
Serial.println(vA+vB); // this does not work
Thanks for your support!