Is it true that reinterpret_cast wont change the values of the pointer it cast, even if the new pointer is a illegal one:
char * charbuffer = ....//charbuffer is a buffer we allocated.
int * Ptr=reinterpret_cast< int *>(charbuffer+17);//Ptr should be illegal due to mis-aligment
I assume even if the address pointed by charbuffer+17
(which is char *
pointer type) is a illegal one to store values of int type due to mis-alignment, Ptr get by reinterpret_cast is still pointed to the same memory address as charbuffer+17
?
Note that we don't care about the contents it pointed to, we just want to make sure the memory address this pointer represents is the same as charbuffer+17
.
Such promise is very important for the correctness and portability of some piece of codes we reviewed.