Original Post
Can I use reinterpret_cast to add or remove const-ness? Now I know const_cast can, but more specifically is something like the following kosher?
From what I understand, reinterpret_cast is only valid if you cast the pointer back to its original type, but does the const modifier play into this (and what about volatile)? The above code example works in MSVC, but just cause it works doesn't mean its proper C++.
void PrintInt (const void* p) { cout << *reinterpret_cast<const int*>(p) << endl; }int a = 5;const int b = 6;PrintInt(&a);PrintInt(&b);From what I understand, reinterpret_cast is only valid if you cast the pointer back to its original type, but does the const modifier play into this (and what about volatile)? The above code example works in MSVC, but just cause it works doesn't mean its proper C++.