Given a void
pointer, if I want to make the void
pointer point to x
bytes ahead, how will this be best done? Is there a better way than casting to a char
pointer?
Given a void
pointer, if I want to make the void
pointer point to x
bytes ahead, how will this be best done? Is there a better way than casting to a char
pointer?
Is there a better way than casting to a char pointer?
No (except having a char *
instead of a void *
to begin with, so you don't have to cast it at all).
If this is not desirable or possible, then the only way is:
ptr = static_cast<char *>(ptr) + offset;
(Note: if you are doing this sort of stuff in C++, usually there is a much better solution. Unless you are an expert and you already ruled out every other alternative, I suggest you post a new question asking if there is a better way to do what you're trying to do!)