For some reason, I catch a conversion error from void * to char * when using the malloc function.

char *strLine = (char *)malloc(256); strLine = memset(strLine, 0x00, 256); 

The error occurs exactly in the second line. The compiler points out to me, they say, dear user, that you incorrectly declared the strLine variable. Googled - found a very similar problem, too, using malloc , but everything was decided by adding this ** (char *) ** before malloc. So what's the deal? Why doesn't it help me?

  • The code is essentially sishny. But due to compiling in C ++ mode, void* implicitly converted to char* . - αλεχολυτ

1 answer 1

Well, the problem you have in the second line, but not in the first: strLine has type char* , and memset returns void* .

You could cast the value returned by memset in char* . But you basically do not need it. Just write

 memset(strLine, 0x00, 256); 

All the same, you have already allocated memory, nothing new from memset will come to you.

  • @Nikolas: In vain you deleted the answer, it is correct. - VladD