Get the address
void* is a “pure” address which doesn’t carry the type information anymore. If you need the type information (e.g. to recover the variable itself in a type safe manner), use a pointer to the appropriate type instead; in this case
Set the address
While C++ doesn’t directly support putting a variable at a given address, the same effect can be achieved by creating a reference to that address:
Overlaying of variables is done with anonymous unions; however at global/namespace scope such variables have to be static (i.e. local to the current file):
C++ only: An alternative (and cleaner) solution is to use references:
Note that in this case, the variables can be non-static.
Content is available under GNU Free Documentation License 1.2.