I am fairly certain that subtracting one uint8_t
from another should result in another unsigned number, but some of my results are confusing me.
uint8_t a = 2;
uint8_t b = 1;
uint8_t c = -a;
long d = b - a;
long e = b + c;
When I obtain the value of d
it produces -1
, while e
is as I would expect 255
. This is a bug with the version of gcc
I am using.....right?
For reference I am using the arm-none-eabi-g++
compiler for my MSP-432
.
Looking at this seems to indicate that gcc
just seems to make the same mistake here.
Looking at this SO question it seems that godbolt and the arm gcc is wrong.
What is going on here?