title: C Dynamic Array of void pointers
body: <p>OK, so I've got the following C code:</p>
  
  <pre><code>//for malloc
  #include &lt;stdlib.h&gt;
  
  //to define the bool type
  #if __STDC_VERSION__ &gt;= 199901L
  #include &lt;stdbool.h&gt;
  #else
  typedef int bool;
  #endif
  
  //define structs
  typedef struct A{
     int integerValue;
      char characterValue;
  } A;
  
  typedef struct B{
      float floatValue;
      bool booleanValue;
  } B;
  
  int main(int argc, const char * argv[])
  {
      //allocate a void pointer array
      void* myArray[3];
  
      //fill the array with values of different struct types
      myArray[0] = malloc(sizeof(A));
      myArray[1] = malloc(sizeof(B));
      myArray[2] = malloc(sizeof(A));
  }
  </code></pre>
  
  <p>but I want to be able to dynamically resize the array. I know that you can dynamically resize an array containing just one type like this:</p>
  
  <pre><code>int* myArray;
  myArray = malloc(3*sizeof(int));
  myArray[0] = 3;
  
  myArray = realloc(myArray,4*sizeof(int));
  printf("%i",myArray[0]);
  </code></pre>
  
  <p>but how would you do this in the upper situation (it needs to be able to handle a virtually infinite number of types). Would it work to reallocate the array with <code>realloc(myArray,newNumberOfIndices*sizeof(ElementWithBiggestSize))</code>, or is there a more elegant way to achieve this?</p>