Skip to main content
gamedev.net
🔒 Locked

pointer question

Started by CProgrammer 4 replies 250+ views
Original Post
CProgrammer
CProgrammer
How can I make a pointer point to a desired address in Memory like say hexadecimal address 0x00FF00F0
superdeveloper
superdeveloper
a quick way is:



char * GetPointer(unsigned int myAddress) {
union {
char * thePointer;
unsigned int theValue;
} myConvertor;

myConvertor.theValue = myAddress;

return myConvertor.thePointer;
};



This is a very basic technique, and there are probably 100 ways to do the same thing. The assembly code is actually quite small, since all my syntax here is just "c" fluff, where no asm is generated, thus performance should be fast..
Mayrel
Mayrel
What''s wrong with ((void *) 0x00FF00F0)?

CoV
CProgrammer
CProgrammer
Both versions work great. However if I use the following to display the address: cout<<&pointer<Its not the same as what I entered.
Why?
-CProgrammer
Mayrel
Mayrel
Because "&pointer" is the address of the pointer variable, not the address of the object that the pointer points at. The address of the object that the pointer points at is just "pointer".

CoV
CProgrammer
CProgrammer
Ay, offcourse, thanks
-CProgrammer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.