This example has overhead, yes.
Originally Posted by tra86
As soon as you take the address of a variable it must be stored in memory. So if i1 was in a register, it's not anymore.
Then the final line must reload from the address of pc. This is because the contents of that memory address could have changed by another process/thead since we wrote to it.
You're also declaring new pointer variables which need to be stored somewhere, and that'll have register usage or stack cost.
I think for this example it is possible for the compiler to optimise and assign the constant 2 to both variables.
int i = 1;
char c = 2;
i = (int)c; // overhead -- value of c must be sign extended
c = (char)i; // overhead -- value of i must have top bits masked