title: The Purpose of a Void Pointer
body: <ul>
  <li>Platform: Linux 3.2.0 x86 (Debian Wheezy)</li>
  <li>Compiler: GCC 4.7.2 (Debian 4.7.2-5)</li>
  </ul>
  
  <p>I am writing some functions similar to memset(), memcpy(), etc. in string.h. I use void pointers to avoid making the functions type specific. But I do not know why I ask for a void pointer when I use a char pointer to dereference the void pointer. It seems to me that the void pointer does not do anything. So my question is what does a void pointer do? For an example here is one of my functions.</p>
  
  <pre><code>size_t damlocs(size_t sizele, void *val, size_t valsiz, void *ele, size_t elesiz)
  {
              //All that 'ele' is used for is this assignment
      char *elebyt = ele;
      char *valbyt = val;
      size_t eleind = 0;
      size_t elebytind = 0;
      size_t valbytind = 0;
  
      if(elebyt &amp;&amp; valbyt)
      {
          while(eleind++ &lt; elesiz)
          {
              elebytind = eleind * sizele;
              valbytind = 0;
  
              while(elebyt[elebytind++] == valbyt[valbytind++])
                  if((valbytind + 1) / sizele == valsiz)
                      return eleind + 1;
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Description: damlocs() will locate the sequence pointed to by 'val' within 'ele[0]' to 'ele[elesiz - 1]' and return the element at which the beginning of the sequence was found. If the sequence is not found zero will be returned. It is similar in concept to bsearch() declared in stdlib.h but a byte to byte comparison is used instead.</p>