You cannot perform arithmetic on a void pointer because pointer arithmetic is defined in terms of the size of the pointed-to object.
You can, however, cast the pointer to a char*
, do arithmetic on that pointer, and then convert it back to a void*
:
void* p = /* get a pointer somehow */;
// In C++:
p = static_cast<char*>(p) + 1;
// In C:
p = (char*)p + 1;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…