This all works just fine. But then I want to store the value stored in heap_listp in the place where first_free points to (offset by 4 bytes). (Note: I can't use &something - this is just an illustration).
So I type: *(first_free + 4) = heap_listp;
but I get this error:
assignment makes integer from pointer without a cast
*(first_free + 4) = heap_listp;
The right operand is type char pointer, but the left is type char cuz it's dereferenced. They don't match.
Do this instead: *(first_free + 4) = *heap_listp;
Thanks. That makes the program compile, but it doesn't do what i want. That takes the value stored at where heap_listp points to and copies it to where first_free points to (offset by 4 bytes). I don't want that value. I want the value of the pointer itself.
Say heap_listp points to memory address 0xeb649010. At that address is the number 2. first_free points to the address 0xeb649018. In memory location 0xeb64901c, I am trying to store the *value* 0xeb649010. The change you suggested places the value 2 at memory location 0xeb64901c. Make sense????
You could use a pointer to pointer.
You should also look into void pointers, but I won't complicate the example.
1 2 3 4
char **ppv;
ppv = reinterpret_cast<char **> (0xeb64901c); // force pointer's value
*ppv = reinterpret_cast<char *> (0xeb649010); // store memory address value there