Pointer arithmetic when void has unknown size [closed]

Incrementing a pointer is technically supposed to increment it by whatever size of thing that its pointing at. Void points at nothing, so the size is unknown.

Its a nicety for some compilers to let you increment void pointers.

Casting is annoying, because you have to either cast it to another pointer, and then back, or do something awkward like (*(char *)&voidptr) += 6

Personally, I’d just declare it as a char * for purposes of arithmetic

Leave a Comment