I understand typecasting...but only in retrospect. My process to figure out what requires typecasting in expressions is usually retroactive because I can't predict when it will be required because I don't know how the compiler steps through them. A somewhat trite example:
int8_t x = -50;
uint16_t y = 50;
int32_t z = x * y;
On my 8-bit processor (Freescale HCS08) sets z
to 63036 (2^16 - 50^2). I can see how that would be one possible answer (out of maybe 4 others), but I would not have guessed it would be the one.
A better way to ask might be: when types interact with operators (+-*/
), what happens?