Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2036: 'void *' : unknown size

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?

like image 444
ProEns08 Avatar asked May 26 '16 12:05

ProEns08


1 Answers

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);
like image 183
dbush Avatar answered Nov 03 '22 22:11

dbush