1 2 3 4 5
|
// this
bp = (char *)(*(bp + 4));
// is the same as this
bp = (char *)(bp[4]);
|
So basically you're taking the 5th character, then casting that character to a pointer, which is nonsense.
This is a key example of why you
should not cast around compiler errors. If what you are doing makes sense, then you usually should be able to do it without casting. If the only way to shut the compiler up is to cast it, then it's a sign that you're probably doing something wrong.
In this case, if you want to increase the pointer so it points to 4 chars after where it does now, then all you have to do is increase it:
That's it.
EDIT
I just realized I misunderstood what you were asking. Whoops!
Anyone know how to extract an address stored at a memory location and convert that back into a pointer? |
The question I have to ask is why would an address be stored in a char*? Shouldn't it be a char**?
At any rate, what you are trying to do is this:
1 2
|
char** bp2 = reinterpret_cast<char**>(bp);
bp = bp2[1];
|
Or if you want to condense it to a one liner:
1 2 3 4
|
bp = (reinterpret_cast<char**>(bp))[1];
// or...
bp = *(reinterpret_cast<char**>(bp + 4)); // caution!
|
Note that the 2nd form assumes sizeof(char*) == 4, which may not always be the case.