Someone recently brought it up that this:
uint8_t a = 0b10000000;
int8_t b = *(int8_t*) &a;
is undefined behavior, because the value of a is outside of what I can represent in int8_t. Can someone explain why exactly this is undefined behavior?
My main issue is that the memory is there, and is valid as the memory for int8_t, the only difference is that int8_t will interpret that byte as -128, while uint8_t will interpret it as 128. I am further confused by this because the fast inverse square root uses:
float y = /* Some val*/;
int32_t i = * ( int32_t * ) &y;
This will give a value of i in essence unrelated (apart from the IEEE standard) to y, so I don't see why reinterpreting a piece of memory could be undefined behavior.