I do not understand what you mean by
copying to `void* buffer`
but if you do the following, then path1 is correct
int main() { int i; char a[10]; void *buffer; buffer = &a; // buffer is void* type pointer and its pointing to some buffer then for(i = 0; i < 10; ++i) { uint8_t temp = 65; //copy to void* buffer *(uint8_t *)(buffer + i) = temp; //WAY
BIG Edit:
IN WAY1
you add + i offcet with void * buffer and yet the whole result is void *, then you attribute the exact result with uint8_t *, then add this value to make it work
but in path2 you add + i offcet with void * buffer, yet the whole result is invalid * and then you get this value ... which is completely wrong. you will get a warning / error here
warning: dereferencing 'void *' pointer
Another Edit:
you cannot dereference the void * pointer, but you can perform an arithmetic operation on the pointer value (not its pointe value)
source share