-
void* error
hi all!
I have a c program and at some point I do:
Code:
void *a;
allocate(&a);//function that allocates a pointer--this works ok
memcpy(&b,a+25*sizeof(c),sizeof(int));//c is a struct
the error I get while compiling is :
error: pointer of type 'void *' used in arithmetic
why is that?
-
The error message is self explanatory. Pointer arithmetic (or array indexing) does not work with void pointers.
Pointer arithmetic can only be done if the compiler knows the size of the data the pointer points at. The whole point of a void pointer is that it can point at data of any type, so the size is indeterminate.
-