Reputation: 1914
I am working with a C project using visual studio. I tried to compile the following code:
void shuffle(void *arr, size_t n, size_t size)
{
....
memcpy(arr+(i*size), swp, size);
....
}
I get the following error with Visual studio Compiler:
error C2036: 'void *' : unknown size
The code compile well with GCC. How to solve this error?
Upvotes: 9
Views: 10240
Reputation: 223699
You can't perform pointer arithmetic on a void *
because void
doesn't have a defined size.
Cast the pointer to char *
and it will work as expected.
memcpy((char *)arr+(i*size), swp, size);
Upvotes: 21