does any one know if, for example, I’m writing in c++ the following code:
int a;
void *ptr = &a;
ptr = (char *)ptr + 1; //<-- this is the interesting line;
Does the (char *) only tells the compiler how to address this variable?
Or does it actually add more calculations in run time?
Thanks.
In this case, no extra calculations are done.
However, there are some cases where a cast is technically a conversion, mostly with numeric input. For example the following could introduce runtime code (provided it is not optimised out, which in a small example like this you’d expect it to be):
Here the internal representation of an int and a double means you cannot just change how the compiler sees the variable, you have to change the data as well.