samedi 9 septembre 2017

Why it is not safe casting a pointer to a numeric type?

consider this code

T* pa = new T(13);
int address = reinterpret_cast<int>(pa);

Where T can be any built-in type.

1) I can not understand what's wrong with reinterpret cast here ??

2) What are the cases when this kind of casting will lead to an undefined behavour ?

3) Will pa always contain the correct decimal representation of a memory address ?

Aucun commentaire:

Enregistrer un commentaire