title: Dynamic array with struct that contains a union in C
body: <p>I'm kind of new to C, so please bear with me.
  I have a struct that contains union of other structs with variable sizes like this:</p>
  
  <pre><code>typedef struct _obj_struct {
      struct_type type;
      union obj {
          struct1 s1;
          struct2 s2;
          struct3 s3;
      } s_obj;
  } obj_struct;
  
  typedef struct _t_struct {
      unsigned int number_of_obj;
      obj_struct* objs;
      other_struct os;
      unsigned int loop;
  } t_struct;
  </code></pre>
  
  <p>The struct_type is the type of the struct we use in the union.
  How do I go through all elements in the objs?
  Is this the right way to do this: </p>
  
  <pre><code>struct1 s1;
  struct2 s2;
  struct3 s3;
  
  for (j=0; j&lt;t_struct.number_of_obj; j++)
  {
      switch (t_struct.obj[j].type) {
          case STRUCT1:
              s1 = t_struct.objs[j].s_obj.s1;
              break;
          case STRUCT2:
              s2 = t_struct.objs[j].s_obj.s2;
              break;
      }
  }
  </code></pre>