My search foo seems lacking today.
I would like to know if it is legal according to std C++ to inspect "any" memory location via an (unsigned(?)) char*. By any location I mean any valid address of an object or array (or inside an array) inside the program.
By way of example:
void passAnyObjectOrArrayOrSomethingElseValid(void* pObj) {
unsigned char* pMemory = static_cast<unsigned char*>(pObj)
MyTypeIdentifyier x = tryToFigureOutWhatThisIs(pMemory);
}
Disclaimer: This question is purely academical. I do not intend to put this into production code! By legal I mean if it's really legal according to the standard, that is if it would work on 100% of all implementations. (Not just on x86 or some common hardware.)
Sub-question: Is static_cast
the right tool to get from the void* address to the char* pointer?
reinterpret_cast
- they can't search for C-style casts. In addition, C-style casts can become even worse casts without warning, likeconst_cast
. – Abrahan