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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With