title: Using unsigned char instead of char because of its range
body: <p>I've been working on a small pure C client application (my first :/) which uses TCP socket for communication with the server. The Server sends me a packet (C structure) in which the first byte contains the size of the packet.</p>
  
  <p>The problem is that server is using unsigned char to represent the size of the packet because char is signed (from -128 to +127) and +127 is not enough to represent size that can be up to 255 in some packets. => I need a unsigned char buffer;</p>
  
  <p>In Linux, the second parameter of recv() function is void * which means I can declare a void *buffer and there is no problem. But recv() in Windows (MinGW) has char * instead of void *. Which give me warning "Parameter type mismatch: Incompatible pointer types 'char *' and 'unsigned char *'"</p>
  
  <p>Is it possible to solve this problem? Here is the code. Thanks.</p>
  
  <p>PS: I'm using NON BLOCKING sockets.</p>
  
  <pre><code> int recvsize = 0;
  unsigned char tmpsize;
  int index = 0;
  unsigned char *buffer;
  
  while (1) {
  
      recvsize = recv(server, &amp;tmpsize, sizeof(unsigned char), 0); // every packet starts with one byte where is its length
  
      if (recvsize &gt; 0 ) {
           buffer = malloc(tmpsize * sizeof(unsigned char)); //memory allocation according to the size of packet
           buffer[0] = tmpsize--; //get back the size value to the buffer
           recvsize = 0;
  
  
          do { //loop over and over until you do not have all bytes of the packet
              recvsize = recv(server, &amp;buffer[++index], tmpsize, 0);
  
              if (recvsize == 0)
                  break;
  
  
              tmpsize -=recvsize;
              index += recvsize;
  
          } while (tmpsize != 0);
  
      }
  sleep(50);
  }
  </code></pre>