I have the memory location of a struct stored as an integer. How can I retrieve the struct stored at that location and make a pointer to the object at that location?
Structure object;
int memLocation = &object;
Structure objectCopy = (objectAtLocation) memLocation;
Structure *objectPointer = (pointerToLocation) memLocation;
Using
ints instead of pointers is very bad form, going back even to the first edition of K&R. So what you’re doing is bad. But assuming you have no choice…if
Objectis aStructure, then&objectis aStructure *. So the proper un-cast is basically your line 3: