How can one portably perform pointer arithmetic with single byte precision?
Keep in mind that:
char
is not 1 byte on all platformsCast the pointer to a uintptr_t
. This will be an unsigned integer that is the size of a pointer. Now do your arithmetic on it, then cast the result back to a pointer of the type you want to dereference.
(Note that intptr_t
is signed, which is usually NOT what you want! It's safer to stick to uintptr_t
unless you have a good reason not to!)