i'm working in C. What I'm trying to do is a function that will return an int containing an address pointing to an object. Then, use the int I received (containing the address), and build a pointer pointing to this address.
Example :
MyClass* obj = SomeMethodReturningAPointerOfMyClass();
int address = (int) &obj;
return address;
I think it works for this part. The value I get is -4197276. (Maybe I'm totaly wrong?)
Then, on the other part, I'd like to do something like :
MyClass* obj = (MyClass*) address;
which doesn't work as I can't access any method of obj without getting an error.
I found a way to do it :
MyClass* obj = SomeMethodReturningAPointerOfMyClass();
machine->registers[2] = (int)obj;
then, in the other method where I receive the integer I did :
MyClass* obj = (MyClass*)address;
I can work on the obj perfectly! Might not be so clean but it should do the job for what it's used for!
Thanks to everyone who took the time to answer!