Void Pointer Arithmetic
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!)
Take a look at this question, and this question. To summarise, the answer is to cast to char *
for arithmetic at a byte level.